Trouble with Docker 7.3-FPM image

I’m having trouble with the 7.3-fpm image for Docker. I take it that it isn’t a turnkey solution and requires some work. I build and up the image with the following docker-compose YAML:

php:

php:
image: yiisoftware/yii2-php:7.3-fpm
build: ./docker-env/php
volumes:
  - ~/.composer-docker/cache:/root/.composer/cache:delegated
  - ./:/app:delegated
ports:
  - '8080:80'
  - '8443:443'
  - '9000:9000'
  - '9005:9005'
environment: 
  - PHP_ENABLE_XDEBUG=1

And this DockerFile:

FROM yiisoftware/yii2-php:7.3-fpm

COPY xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini

I try my application at the address on port 8080, and 8443, but it gives a connection refused error.

I’m using Docker Virtualbox on Windows 10 Home with the following ports forwarded through the interface:

80:80
443:443
3306:3306
64618:22
9005:9005
9000:9000

I had initially tried out the apache tags and my web app worked perfectly fine. It’s just the FPM tags that aren’t working. What am I missing?

In general, FPM can not works without a web server(nginx/apache/others).

Is there a boilerplate nginx config that can be used?

You can define a docker-compose.yml , includes nginx and php-fpm services.

Here is an example I used before, hope that helps(replace php and nginx images to your own, and delete other unused services):


I have amended my docker-compose file with the following:

php:
  image: yiisoftware/yii2-php:7.3-fpm
  build: ./docker-env/php
  volumes:
    - ~/.composer-docker/cache:/root/.composer/cache:delegated
    - ./:/app:delegated
  ports:
    - '9000:9000'
    - '9005:9005'
  environment: 
    - PHP_ENABLE_XDEBUG=1
nginx:
  image: nginx:1.17
  restart: always
  volumes:
    - ./docker-env/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
    - ./docker-env/nginx/conf.d:/etc/nginx/conf.d:ro
    - ./:/app:ro
    - ./runtime/logs:/app/runtime/logs:rw
  ports:
    - '8080:80'
    - '8443:443'

The DockerFile for the php image is as follows:

FROM yiisoftware/yii2-php:7.3-fpm

COPY xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
COPY www.conf /usr/local/etc/php-fpm.d/www.conf
RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini

Everything builds and ups fine, but I am still getting a connection refused when I try to access the server on 8080. I’m attempting to access on 192.168.99.100, which is the default IP for VBox Docker. I confirm this by being able to connect just fine to my MySql instance that is also upped as part of this docker-compose file.

This is my nginx configuration file that is included in the volumes:

events {

}

http {
server {
    charset utf-8;
    client_max_body_size 128M;

    listen 80; ## listen for ipv4
    #listen [::]:80 default_server ipv6only=on; ## listen for ipv6

    server_name 192.168.99.100;
    root        /app/web;
    index       index.php;

    access_log  /app/runtime/logs/access.log;
    error_log   /app/runtime/logs/error.log;

    location / {
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php$is_args$args;
    }

    # uncomment to avoid processing of calls to non-existing static files by Yii
    #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    #    try_files $uri =404;
    #}
    #error_page 404 /404.html;

    # deny accessing php files for the /assets directory
    location ~ ^/assets/.*\.php$ {
        deny all;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        try_files $uri =404;
    }

    location ~* /\. {
        deny all;
    }
  }
}

What else am I missing here?

The fastcgi_pass should be php:9000(same as the php-fpm service name and port in docker-compose.yml).

Additionally, change server_name as default_server(not sure).

Btw, you can follow these steps for troubleshooting:

  • Check whether all services are set up successfully.
  • Enter the nginx container, and check nginx error.log and /app/runtime/logs/error.log, access.log is an important clue for determining whether nginx receives requests.