IP Address for Container?

Is it possible to have for each Container diffrent ip addresses?

Each container does have their own ip address (172.x.x.x) Perhaps you are referring to something else?

Oh, sorry for my bad spelling.

I mean can i change the ip address of each container. So i need to run their in my local network?

Network: 192.168.20.xxx
Container now: 172.0.0.1
¨
Container i want: 192.168.20.xxx

is this possible and when yes how ?

Folks:

Setting the IP or IPv6 address for a container is fairly straightforward. This can be done at run time. To see how, please check the docker engine documentation, or run this command to find the syntax:

docker run --help | grep ip

The documentation around this can be seen here: Docker run reference | Docker Docs

Best of luck,

Bryce

1 Like

I asked a similar question a while back, but no one answered. I hope someone answers :frowning:

1 Like

Thanks for youre reply.

My Problem now is i cant start the container. I need a Mysql and wordpress container and cant start it with
this ip can you help me with maybe a command for this problem?

I need this foxed as soon as possible :slight_smile:

Thanks

Hi cicada3301!
The “trick” to provide an IP address to a certain container is quite simple:
docker run -d --ip=“192.168.20.173” wordpressmysql

Of course you may use the Docker command start as well, depending on your demands.

I hope this will help you further.

Cheers
Thorsten

what means “-d” ?

And thanks for that support :slight_smile:

Hi Tamino,

the option “-d” means, run as a detached (-d) container. One could also say, that it is running in the background like a daemon.

This means, that you have no terminal to the container (by default). If you start it in the foreground, you can attach a tty terminal to it with the options -i and -t, or -it in short.
Or you can use the “docker attach” command to reattach to a detached container again.

I am so used to start my containers with the -d option, I didn’t realized that I mentioned it here too.

You can find more information about how to run Containers here:
Documentation about the Docker run command:

It is always a great source of tricks and ideas to have a read of the Docker Docs one in a while.

Hi Thorsten

this error comes up i dont know why ?

Whats the problem ?

Can you help me ?

Hi Tamino,

the error message says, that Docker could not found the image mywordpress. Neither locally (on the system you are working on) nor in the repository (usually Docker hub).
Are you sure, that you still have it available?

Did you check with a “docker images -a | grep mywordpress” already?

… and you should decide if you want to run the container as an interactive container with a terminal (-it) or not (-d). :wink:

Hi Thorsten

But i must run my container with this ip not the image because i want an existing container run on this ip not a new image.

I dont get it haha :joy:

Hi Tamino,

in the provided screenshot I can’t see any “mywordpress” image. So Docker is right :wink:
All I see is a “wordpress” image.
So if you try a
docker run -d --ip=“192.168.20.173” wordpress
it should start a wordpress container with the desired ip address. (and run it in detached mode).

If you have a container already running and want to change it’s ip address while running, I am not sure how this can be done. And I wouldn’t take the effort of finding out. I would kill the container and start a new one.

Cheers
Thorsten

Hi Thorsten

So now this error appears:

Problems over problems.

Thanks for youre patience :slight_smile:

@tmichels are you here ?

Hi Tamino!
Now I am there again. Sorry for being not a FTE of Docker support :wink:

Well, the issue becomes more complex the longer we discuss it.
The error message tells you, that you are not using the networking features of Docker, yet.
This is not a five minutes task to solve. Actually, the doing is no rocket-science, but you have to understand these features first, before you can make use of it.
So, please have a read about these features HERE!
It wouldn’t make much sense to tell you in brief, what needs to be done, as this may throw up much more questions than answers.

The main idea is: You create a virtual network over your LAN with the docker commands network …
Then you may create a subnet with the desired ip addresses and so and so forth.
It is not easy, but very powerful.

So in case, you may just need a container to be reachable for other systems and you can’t change the ip address, I would think of a little proxy, apache, nginx, etc to do the redirection for you.

Sorry for being not able to guide you through in detail, but hopefully these hints will help you.

Cheers
Thorsten

2 Likes

Hi Thorsten

Thanks for everything until now. :slight_smile:

I look at the documentation and maybe ive question about ip soon so i will ask you per message.

But thanks a lot.

Regards Tamino

Hi Tamino,

It was my pleasure to help you with the little I wrote. I hope this will lead you into the right direction and get your issue solved.

Cheers
Thorsten

1 Like

I’d recommend that you take a look at this blog post which illustrates docker-compose which may help make it easier for you.

https://fordodone.com/2016/03/30/docker-compose-static-ip-address-in-docker-compose-yml/

Thanks @jliu70

But i dont must inspect i must chang all values.