0

I want to run MS SQL server (docker image: microsoft/mssql-server-windows-developer) in a docker container. Using Windows on the host and the container. Afterwards, the database should be accessible from the host (using SQL Management Studio) by a useful, name (so that the instructions can be re-used). However, docker generates a seemingly random IP, which is not as useful, especially as it resets on every call to run.

So, I would like to give the container a hostname that is accessible from the host machine (e.g. by SQL Management Studio). I'd like to avoid a mere IP here, but it would suffice, if no better solution presents itself.

Creating a network in docker did not work, as this functionality apparently is only supported under Linux.

--network-alias also failed.

The run command looks like this:

docker run -d -p 1433:1433 -e sa_password=1234qwerT -e ACCEPT_EULA=Y --name docker_sql microsoft/mssql-server-windows-developer
Chieron
  • 101
  • 2
  • 2
    `localhost:1433` doesn't suffice? Assuming you're using the standard port, but regardless localhost should work for you. – bluescores Jun 17 '19 at 16:41
  • Also, I'd say go ahead and include the command you're using to run the docker container please. – bluescores Jun 17 '19 at 16:42
  • @bluescores I've added the command. – Chieron Jun 18 '19 at 08:12
  • 1
    @bluescores Of course localhost works, I never tried that one, because I assumed that it would interfere with a theoretical installation of the SQL server on the host machine.. – Chieron Jun 18 '19 at 08:45

2 Answers2

0

This is very similar to this question here: How to get a Docker container's IP address from the host?

I think you can achieve what you want by way of a 2 step process:

  1. Obtain the container id for your container as part of your docker run command.
  2. Use docker inspect to get the container's IP address.

If you really don't want to use the IP address, then you can always add the IP address to your hosts file, but simply using the IP address as a shell variable should be almost as useful.

So, for example, from a bash shell:

CID=$(docker run -d ubuntu /bin/sh -c 'while /bin/true; do sleep 10 ; done')
IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $ID)

Now you can use $IP within scripts as you see fit. (Substitute the CID=... line with whatever docker run command you are using to start your container).

John
  • 10,837
  • 17
  • 78
  • 141
  • I need something tangible, not a random IP address that will be renewed after each run command. The IP is not needed in the scripts but for connection in the SQL Management Studio. I know how to get it, but require something a bit more accessible. – Chieron Jun 17 '19 at 22:43
0

As per bluescores' comment and stumbling upon this related question, I tried and verified that connecting to localhost is possible - so there actually is no need to configure a name for the container-sql-server or to configure its IP.

The general problem might persist for other applications, but for what I want to achieve currently, localhost will suffice.

Chieron
  • 101
  • 2