Answer the question
In order to leave comments, you need to log in
Docker: Why is the local IP address of the host machine unreachable for connections within the cluster?
Good day everyone!
On a host with Ubuntu 20, a cluster of several containers was raised, interconnected into one network.
The cluster is an nginx + php-fpm + mysql + memcached + redis development stack.
The host address on the local network is 192.168.1.104. Until today, all containers freely "communicated" with each other using this IP, and suddenly this address became unavailable to them. It was required to explicitly prescribe the network names of each container in all configs. I understand that it was originally more correct, but I don’t understand why this happened?
Access to the samba server 192.168.1.104 from LAN has fallen off to the heap, but the web cluster itself is still accessible from other machines on the network on the 80th port. Maybe it's not related, but still. I am attaching docker-compose for clarity.
version: '3'
services:
#PHP
php:
build:
context: ./image/php/${PHP_VERSION}/.
image: openweb/php:${PHP_VERSION}
container_name: os-php${PHP_VERSION}
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./www:/var/www
- ./config/php/php.ini:/usr/local/etc/php/php.ini
- ./scripts:/bin/app
networks:
- openweb-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: os-nginx
restart: unless-stopped
tty: true
ports:
- "${WWW_PORT}:80"
- "${WWW_SECURITY_PORT}:443"
volumes:
- ./www:/var/www
- ./config/nginx/:/etc/nginx/conf.d/
- ./scripts:/bin/app
networks:
- openweb-network
#MySQL Service
mysql:
image: mysql:5.7.24
container_name: os-mysql5.7.24
restart: unless-stopped
tty: true
ports:
- "${MYSQL_PORT}:3306"
volumes:
- ./db/mysql:/var/lib/mysql
- ./scripts:/bin/app
environment:
MYSQL_ROOT_PASSWORD: "${MYSQL_PASSWORD}"
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- openweb-network
#Redis Service
redis:
image: redis
container_name: os-redis
restart: unless-stopped
tty: true
ports:
- "${REDIS_PORT}:6379"
volumes:
- ./db/redis:/var/lib/redis
- ./scripts:/bin/app
environment:
- REDIS_REPLICATION_MODE=master
networks:
- openweb-network
#Memcached
memcached:
image: memcached
container_name: os-memcached
restart: unless-stopped
tty: true
ports:
- "${MEMCACHED_PORT}:11211"
networks:
- openweb-network
#Docker Networks
networks:
openweb-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
Answer the question
In order to leave comments, you need to log in
here read how the network works in compose
https://docs.docker.com/compose/networking/
for your case, you should probably pay attention to two sentences
By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.
Instead of just using the default app network, you can specify your own networks with the top-level networks key. This lets you create more complex topologies and specify custom network drivers and options. You can also use it to connect services to externally-created networks which aren't managed by Compose
The host address on the local network is 192.168.1.104. Until now, all containers freely "talked" to each other using this IP
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question