Search code examples
sql-serverdockerdocker-machine

Choosing Container ports numbers


Please see the command below:

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Password1" -p 1433:1433 -d microsoft/mssql-server-linux:2017-latest

After I run this command I can connect to the database using SQL Studio manager as shown below:

enter image description here

I can also connect using: 192.168.99.100,1433. Next I remove the container and execute the following command:

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Password1" -p 600:600 -d microsoft/mssql-server-linux:2017-latest

I have made up the port here. Now, please see the screenshot below:

enter image description here

1) Why is the tcp port 1433?

2) Why can I not connect to the database on port 500?

I realise the documentation tells you to use port 1433 as shown here: https://hub.docker.com/r/microsoft/mssql-server-linux/. However, it does not tell me why.


Solution

  • (1) The image Dockerfile presumably says EXPOSE 1433 because that's the port the server listens on; the bare 1433/tcp output in docker ps means that port isn't published to the host.

    (2) When you docker run -p 600:600, you tell Docker to forward port 600 on the host to port 600 in the container. Nothing's listening on that port, so you can't connect.

    (3) If you docker run -p 600:1433, you'd tell Docker to forward port 600 on the host to port 1433 in the container, where the server is listening, and I would expect this to work.