E
E
EvgMul2021-02-15 21:18:16
Nginx
EvgMul, 2021-02-15 21:18:16

Why is the nginx container not working correctly?

Hello. I have a docker-compose.yml with the following content:

version: '3'

services:
  rabbit:
    hostname: rabbit
    image: rabbitmq:3.6.1-management
    environment:
      RABBITMQ_DEFAULT_USER: admin
      RABBITMQ_DEFAULT_PASS: admin
    ports:
      - "5672:5672"
      - "15672:15672"
    healthcheck:
      test: [ "CMD", "pwd" ]
      timeout: 3s
      retries: 20
    networks:
      - internal
  php:
    build:
      dockerfile: Dockerfile
      context: ./
    volumes:
      - ./:/var/www/html
      - ./docker/conf/php/custom.ini:/usr/local/etc/php/conf.d/custom.ini
    depends_on:
      db:
        condition: service_healthy
      rabbit:
        condition: service_healthy
    environment:
      XDEBUG_CONFIG: client_host=host.docker.internal
      PHP_IDE_CONFIG: "serverName=Docker"
    networks:
      - internal
  db:
    image: mysql:latest
    environment:
      MYSQL_DATABASE: mailing
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: user
      MYSQL_PASSWORD: user
    healthcheck:
      test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
      timeout: 3s
      retries: 20
    ports:
      - 3306:3306
    volumes:
      - ./database:/var/lib/mysql
    networks:
      - internal
  nginx:
    image: nginx:1.19.2-alpine
    ports:
      - 8000:80
    volumes:
      - ./:/var/www/html
      - ./docker/conf/nginx:/etc/nginx/conf.d
      - ./docker/nginx/logs:/var/log/nginx/
    links:
      - php
    networks:
      - internal
    depends_on:
      db:
        condition: service_healthy
networks:
  internal:
    driver: bridge
    ipam:
      driver: default


If I raise this whole thing, then when I access localhost: 8000 I see an error
502 Bad Gateway
connect() failed (111: Connection refused) while connecting to upstream, client: 172.23.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://172.23.0.4:9000", host: "localhost:8000"

Moreover, static files such as image files, style files, etc. nginx returns correctly. It looks like it's in php.

But if I remove the depends_on section for the php container, then everything works correctly.
Tell me, please, how to solve this problem?
Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Karasik, 2021-02-16
@vitaly_il1

But if I remove the depends_on section for the php container, then everything works correctly.

I think something is wrong with the healthchecks. Maybe write something in the log?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question