M
M
MikUrrey2021-05-05 19:15:55
Computer networks
MikUrrey, 2021-05-05 19:15:55

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.

docker-compose

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


PS Criticism on setting up a cluster - believe the welcome, because I set it up on the basis of a finished assembly and I'm not sure that everything is perfect (at night, I'm sure it's not perfect).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
iddqda, 2021-05-06
@MikUrrey

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

in short, if you do NOT specify networks in docker-compose, then compose uses the default bridge and links containers by name to each other.
If you specify a custom network (openweb-network in your case), then you will have to fiddle with the names yourself
and this ...
The host address on the local network is 192.168.1.104. Until now, all containers freely "talked" to each other using this IP

no, that's not how it works. Containers have their own openweb-network. The address can be viewed with the
docker network inspect openweb-network command

M
MikUrrey, 2021-05-07
@MikUrrey

Unfortunately, the moderator did not carefully read the question How to make the network of the host machine "visible" in the docker network? and marked it as a duplicate of this question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question