-3

I am new to docker, and couldn't find answer to my question anywhere else... I want to assign static ip addresses to my docker containers, but don't know how to... Does is mean that I need to buy static ip for my device?

Please helppp!!!

Thank you in advance

  • A Docker container appears (via the `docker run -p` option) like any other process running on your host. If you otherwise assign static IP addresses to individual processes, the same setup will work for Docker, but that would be a pretty unusual setup. – David Maze Sep 17 '20 at 12:12

1 Answers1

0

Don't try to add a static IP to a docker container. Docker containers are meant to be stopped and started frequently and everytime they will have a new IP address. Furthermore, one containerized application can be scaled up and down by changing the number of container instances from the same image. Therefore a static IP won't make sense. The Docker daemon has a built in DNS that makes sure that you can target your containers by referring to them by their container name. For example:

docker run -d -p 8080:80 --name <custom_container_name> <image>

Then you can reference the container via it's name:

ping <custom_container_name>:8080
hatati
  • 379
  • 2
  • 7