Hello! Help please set up a working environment using the docker. Shoveled Russian and English SO, but did not find a suitable solution. I try to make a development environment using Docker, nginx, php, mysql. On a Ubuntu 18.04 host. I enter

docker-compose up -d --force-recreate --build 

Nginx, php, mysql start, work, but the site in the browser does not open. The request leaves, but there is absolutely nothing in return. The browser writes "Hmm. We can't find this site." And it's not clear where the problem is, with the network between the host and the docker or with the docker-compose.yml settings docker-compose.yml here is this content:

  version: '3.7' services: nginx: image: nginx:1.12 restart: always ports: - "8080:80" - "4430:443" expose: - "80" networks: - bridge volumes: - ./hosts:/etc/nginx/conf.d - ./www:/var/www - ./logs:/var/log/nginx tty: true command: nginx -g "daemon off;" php: build: ./images/php volumes: - ./www:/var/www expose: - "9000" networks: - bridge mysql: image: mysql:5.7 volumes: - ./mysql:/var/lib/mysql expose: - "3306" networks: - bridge environment: - MYSQL_ROOT_PASSWORD=password - MYSQL_DATABASE=devbd - MYSQL_USER=devuser - MYSQL_PASSWORD=password networks: bridge: driver: bridge 

The nginx config has the following form:

 server { listen 80; server_name dev-php.local *.dev-php.local; root /var/www; index index.php index.html; error_log /var/log/nginx/dev-php-error.log; access_log /var/log/nginx/dev-php-access.log; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; try_files $uri =404; fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 

Dockerfile for php image:

 FROM php:7.0-fpm RUN apt-get update && apt-get install -y \ curl \ wget \ git \ libfreetype6-dev \ libjpeg62-turbo-dev \ libmcrypt-dev \ && docker-php-ext-install -j$(nproc) iconv mcrypt mbstring mysqli pdo_mysql zip \ && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ && docker-php-ext-install -j$(nproc) gd \ # RUN yes | pecl install xdebug \ && pecl install xdebug \ && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \ && echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \ && echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer ADD php.ini /usr/local/etc/php/conf.d/40-custom.ini WORKDIR /var/www CMD ["php-fpm"] 

    1 answer 1

    In this configuration, your client (browser) is knocking on the default port 80, which you have closed. The expose directive opens the port only on the internal network (for related services) for php and mysql in your case.

    To make it work, open localhost:8080 in the browser (you have it in the docker-compose file, you are prompted for port 80 of the nginx container), or in ports nginx add 80:80 . For HTTPS connections, either localhost:4430 or ports 443: 443

    • thanks for the answer, but for nginx I have specified ports: - "8080: 80" I tried to log in through localhost: 8080, writes "Connection attempt failed". Also, if you go to the container IP nginx 172.22.0.4:8080 (it pings) - Webs F
    • one
      @websf you have nginx listening to the host dev-php.local and * .dev-php.local. And you send him the host localhost or IP. Therefore, try adding dev-php.local 127.0.0.1 to your / etc / hosts file on your Ubuntu host or in nginx change the host to localhost - Evgeny
    • docker ps issues this here 0.0.0.0:8080->80/tcp, 0.0.0.0:4430 for nginx It seems like any address is obtained. This / etc / hosts dev-php.local 127.0.0.1 tried. It does not go. - Webs F
    • The problem was solved, the nginx config file extension was incorrect. It was test-site.config suggested what you need to do default.conf and should pick up, made, earned. - Webs F