I am trying to set a static IP on my docker-compose v3 file but.. i can't.
Each time I set it, I can't connect to the webpage anymore.
I am getting ERR_ADDRESS_UNREACHABLE
Here is my config:
# docker-compose.yml
version: '3'
services:
web:
build: ./etc/nginx
ports:
- "90:80"
volumes:
- "./etc/ssl:/etc/ssl"
depends_on:
- php
- database
php:
build: ./etc/php
ports:
- 9000:9000
links:
- database:mysqldb
volumes:
- "./etc/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
- ${APP_PATH}:/var/www/symfony
database:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
ports:
- 3300:3306
volumes:
- "./data/db/mysql:/var/lib/mysql"
and
# docker-compose.override.yml
version: '3'
services:
web:
networks:
test:
ipv4_address: '10.1.0.100'
networks:
test:
ipam:
driver: default
config:
- subnet: 10.1.0.0/24
Static IP addresses don't change when containers or services are stopped and started, making them useful for permanent networking. Assigning Docker containers static IP addresses is an easy way to make them more accessible.
depends_on is a Docker Compose keyword to set the order in which services must start and stop. For example, suppose we want our web application, which we'll build as a web-app image, to start after our Postgres container.
It should be like this:
services:
web:
networks:
test:
ipv4_address: 10.1.0.100
networks:
test:
driver: bridge
ipam:
driver: default
config:
- subnet: 10.1.0.0/24
And in my case I placed networks
section before services
.
UPDATE:
eventually I've ended up using external network for like this:
docker network create --subnet 10.5.0.0/24 local_network_dev
and then in any docker-compose you can just use it like this:
version: '3.2'
networks:
default:
external:
name: local_network_dev
and inside of image:
web:
networks:
default:
ipv4_address: 10.5.0.11
# Use root/example as user/password credentials
version: '3.3'
networks:
netBackEnd:
ipam:
driver: default
config:
- subnet: 192.168.0.0/24
services:
mongo-db:
image: mongo
container_name: cnt_mongo
restart: always
environment:
MONGO_INITDB_DATABASE: dbArland
MONGO_INITDB_ROOT_USERNAME: maguilarac
MONGO_INITDB_ROOT_PASSWORD: pwdmaguilarac
ports:
- 27017:27017
volumes:
- ./script1_creacion_usuario.js:/docker-entrypoint-initdb.d/script1_creacion_usuario.js:ro
- ./script2_creacion_coleccion.js:/docker-entrypoint-initdb.d/script2_creacion_coleccion.js:ro
- ./script4_carga_productos.js:/docker-entrypoint-initdb.d/script4_carga_productos.js:ro
- ./productos_inicial.json:/docker-entrypoint-initdb.d/productos_inicial.json:ro
- ./mongo-volume:/data/db
networks:
netBackEnd:
ipv4_address: 192.168.0.4
mongo-express:
image: mongo-express
container_name: cnt_mongo-express
restart: always
ports:
- 9081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: maguilarac
ME_CONFIG_MONGODB_ADMINPASSWORD: pwdmaguilarac
networks:
netBackEnd:
ipv4_address: 192.168.0.6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With