peinearydevelopment
peinearydevelopment

Reputation: 11474

How can a dockerfile expose SQL Server as localhost?

Following the documentation on the microsoft/mssql-server-linux page, it provides the following command to get a docker container running.

docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Test!234' -p 1433:1433 -d --name sqllinux microsoft/mssql-server-linux

This works fine and I'm able to open up SSMS and connect to localhost with the credentials:

username: sa

password: Test!234

What I wanted to do after that is to create a Dockerfile that will create the image that will do the same thing:

FROM microsoft/mssql-server-linux

ENV ACCEPT_EULA Y
ENV SA_PASSWORD Test!234

EXPOSE 1433 1433

I then ran docker build . -t sqltestfile followed by docker run sqltestfile.

The container seems to start just fine and through Kitematic I can see (what looks like to me) the same output as running the other image, but I'm not able to connect to this image through SSMS using localhost.

What needs to be changed about the Dockerfile to have it work the way I would expect (can connect to the container instance using SSMS through localhost)?

Any help would be greatly appreciated!

Upvotes: 1

Views: 2228

Answers (1)

Balázs Németh
Balázs Németh

Reputation: 6637

You still need to explicitly publish the port with -p. From the docs:

The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. You can specify whether the port listens on TCP or UDP, and the default is TCP if the protocol is not specified.

The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published. To actually publish the port when running the container, use the -p flag on docker run to publish and map one or more ports, or the -P flag to publish all exposed ports and map them to to high-order ports.

Upvotes: 2

Related Questions