Docker Community Forums

Share and learn in the Docker community.

Please help me clarify my confusion regarding Docker

First time I used Docker was when I wanted to install Laravel and followed their instructions about using Docker + Laravel.

I thought I need WSL2 only for the Ubuntu image because I installed stuff on the Ubuntu OS.

But now, I deleted all images and installed the following:

  1. Installed official NGINX on one container using docker pull nginx - now when I type localhost in my web I can see it’s working

  2. I installed PHP official image using docker pull php - But I have no idea how can I use it. How do I see where is it installed? Maybe I need to install it on top of some Linux OS and not directly on Docker?

Now, I am confused because I was told to install php-fpm and not just php. so I went to the php page of Docker: Docker Hub and clicked on “View avaialble tags” which opened a list of other images available for download.

I am confused - are they official? For example docker pull php:fpm-alpine3.14, Also - it seem to be installed with alpine Linux - so do I have to use some sort of Linux when installing a container in Windows?

Lastly - how would I combine the two? How to make the NGINX container serve the API of Laravel from the PHP-FPM image (in case I understand how to actually use the PHP container)

Hello and welcome,

using Docker and NginX together with PHP is nearly the same as you would do with NginX and PHP on an normal computer :). I don’t go into details for WSL2 (as I use Docker on Linux) but I think you will get the needed infos for integrating NginX and PHP in Docker.

But one thing after the other…

1 - My php-files (i.e. a file called phpinfo.php containing only <?php phpinfo(); ?> for verifying that PHP is working fine) and the static files (*.html, *.jpg, *.css, *.js, …) are located in /srv/www/html on my hosts harddrive.

2 - As I need some tweaks for PHP to upload larger files so I create a file called uploads.ini with this content:

file_uploads = On
memory_limit = 128M
upload_max_filesize = 128M
post_max_size = 128M

3 - I need NginX to know that it should forward requests for *.php to PHP, so I have this file I’ve called default.conf - for this example I have removed all https-stuff, maintenance-mode-things, forwarding to Tomcat, to the webradio, … so that only the PHP-stuff is here:

client_max_body_size 128M;
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    index index.php index.html;
    server_name _;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/html;
    location / {
      # First attempt to serve request as file, then
      # as directory, then fall back to displaying a 404.
      try_files $uri $uri/ =404;
    location ~ \.php {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info;
        fastcgi_param HTTPS $fastcgi_https;
        fastcgi_param PATH_INFO $fastcgi_path_info;

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    location ~ /\.ht {
      deny all;

4 - Now I use this docker-compose.yml to configure what should be done - start PHP and NginX and you will be able to access the PHP-container with the name php which is used in NginX’s config-file above. I also mount my webserver’s document-root into both containers and the config-file into its corresponding container:

version: 3.2

    image: nginx:latest
      - "3080:80"
      - "/srv/www/html:/var/www/html"
      - ./default.conf:/etc/nginx/conf.d/default.conf
      - php
    image: php:7.4-fpm
      - "/srv/www/html:/var/www/html"
      - "./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini:ro"

5 - Now I can start both services with docker-compose up -d and access the webserver with http://<serverip>/phpinfo.php and should see some information about the server and PHP. If you need additional modules for PHP (i.e. mysqli, gd, curl, exif, mongodb, radius, redis, …) you have to build your own image based on php:7.4-fpm. If you need more information on this - feel free to ask :slight_smile: