Docker Community Forums

Share and learn in the Docker community.

Using docker-compose network to give a service a fixed IP address


I’m have several docker containers that are bult from multiple dockfiles using a docker-compose file. They all seem to work and i can connect to them through opc.tcp://localhost:xxx. Rather than bridge these with the host system i’d like to make it appear that these services are separate machines with their own IP address.

From what i understand inorder to do this i need to creat a docker network?

looking through the guides i’ve added the following to one of my services in my docker-compose file.

context: .
dockerfile: ./sample-server/Dockerfile
restart: always
- “7021:7021”

driver: bridge
enable_ipv6: false
driver: default
- subnet:

The conatiner builds ok and i can still connect to it at opc.tcp:localhost:7021 - however i can’t connect to it at the specified IP address

Is there something i’m missing?

Many thanks!

Hello Ollie,

you didn’t mention if you are running a windows-box (with windows-containers or linux-containers) or on a linux-box.
I’ve tested on my linux box and was able to ping a container within my bridge-network by its IP-address.
Whereas on my windows-box running linux-containers I was not able to do so. See Networking features in Docker Desktop for Windows | Docker Documentation for more information.

But usually it is not needed to have fixed ip-addresses for your containers. Let Docker decide which ip to use for which container and simply use port-mapping and/or the container’s names to access one container from another container.

Best regards
Matthias :slight_smile:

Hi Matthais!

Thanks for getting back to me - sorry i’m very new to docker!! :slight_smile:

I’m running these linux containers on my windows machine. My machine has two NICs (one for my VLAN and one for the wider network) i’d like to specify the VLAN and make the containers appear as indepdant machines on thta network.

Do i need to specify a macvlan in docker for this or switch from Bridged to NAT as the driver?

i can also fireup a linux machine and install docker on there if that would be easier?

Would the code work as it is on there to make the conatiner appear as a separate machine?

Thanks again!