fredrik
fredrik

Reputation: 10291

How to set up container using Docker Compose to use a static IP and be accessible outside of VM host?

I'd like to specify a static IP address for my container in my docker-compose.yml, so that I can access it e.g. using https://<ip-address> or ssh user@<ip-address> from outside the host VM.

That is, making it possible for other machines on my company network to access the Docker container directly, on a specific static IP address. I do not wish to map specific ports, I wish to be able to access the container directly.

A starting point for the docker-compose.yml:

master:
  image: centos:7
  container_name: master
  hostname: master

Is this possible?

I'm using the Virtualbox driver, as I'm on OS X.

Upvotes: 2

Views: 2736

Answers (3)

cantSleepNow
cantSleepNow

Reputation: 10202

You could specify the IP address of the container with --ip parameter when running it, so in that it way the IP would always be the same for the container. After that you could ssh to your host VM, and then "attach" to the container.

Otherwise, I'm not sure... Maybe try and run the container with --net=host From https://docs.docker.com/engine/userguide/networking/dockernetworks/

The host network adds a container on the hosts network stack. You’ll find the network configuration inside the container is identical to the host.

Upvotes: 0

Auzias
Auzias

Reputation: 3798

So far it is not possible, it will be in the Docker v 1.10 (that should be released in a couple of weeks from now).

Edit:

See the PR on GH.

Upvotes: 1

ioseb
ioseb

Reputation: 16959

I believe extra hosts entry is a solution.

extra_hosts:
 - "somehost:162.242.195.82"
 - "otherhost:50.31.209.229"

See extra_hosts.

Edit:

As pointed by M. Auzias in comments, i misunderstood the question. Answer is incorrect.

Upvotes: 0

Related Questions