Hello!
Using docker compose, I created container:
version: '3.8'
services:
server:
build:
context: ./server/
container_name: performances-app
depends_on:
db:
condition: service_healthy
ports:
- "8083:5000"
restart: on-failure
networks:
custom_net:
ipv4_address: 172.18.0.5
networks:
custom_net:
driver: bridge
ipam:
config:
- subnet: 172.18.0.0/16
gateway: 172.18.0.1
(Its not a matter of question, but just in case I’ll note, that I use static ip in configuration with proxy container, which redirect requests from browser to server, and without explicit static ip, it redirect it each time to different addresses: for example, 172.18.0.1, 172.18.0.2, 172.18.0.3).
I create image from this container and successfully push it to Docker hub.
I’m interested: when I pull this image to another device and create a container, will the network settings be retained in the new container?
Container, created by docker compose, has following network settings:
"Networks": {
"theater-app-client-server_custom_net": {
"IPAMConfig": {
"IPv4Address": "172.18.0.5"
},
"Links": null,
"Aliases": [
"performances-app",
"server"
],
"MacAddress": "62:da:8d:99:28:03",
"DriverOpts": null,
"GwPriority": 0,
"NetworkID": "ec898733f5d18430af465038316a03623fc27d809ead541ed38bb2ddb0ae2481",
"EndpointID": "5cec80296e02684dae68c62a3b78ee739a7353f84aaa8e6b014104e4e369517a",
"Gateway": "172.18.0.1",
"IPAddress": "172.18.0.5",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"DNSNames": [
"performances-app",
"server",
"e33e049aa861"
]
}
}
As I understand, bridge network is used by default, when container created.
But in my case container will work correctly, only if it has network settings with “IPAddress”: “172.18.0.5”
I doubt, that after image pull and container created in new device, this network settings will be saved. As I understand, only default bridge settings will be available.
If that’s the case, what is the best way to create a container in a new environment without using Docker Compose? As variant, I I’ll have to create custom network before container creation in new device? For example, by script:
docker network create
--driver=bridge
--subnet=172.18.0.0/16
--gateway=172.18.0.1
custom_net
And run container with script:
docker run -d --network=custom_net --ip=172.18.0.5 --name performances-app
Or maybe I don’t understand how it works?