title: Docker wordpress + mysql + phpmyadmin + nginx
body: <p>I tried to prepare docker-compose file for my local development project, but I've stuck on setting domain for phpmyadmin.</p>
  <p>I added hosts to to hosts file on windows.</p>
  <pre><code>127.0.0.1 phpmyadmin.test
  127.0.0.1 wordpress1.test
  127.0.0.1 worpresss2.test
  </code></pre>
  <p>My dev folder's structure:</p>
  <pre><code>dockerfiles/
     |-wordpress1
       - Dockerfile
     |-wordpress2
       - Dockerfile
  .docker/nginx/conf.d/
     - nginx.conf
     - phpmyadmin.conf
  sites/
  docker-compose.yml
  </code></pre>
  <p>docker-compose.yml:</p>
  <pre><code>version: '3.7'
  
  services:
    # Nginx Service
    nginx:
      image: nginx:1.17-alpine
      ports:
        - 80:80
      volumes:
        - ./sites:/var/www/html
        - ./.docker/nginx/conf.d:/etc/nginx/conf.d:ro
        - phpmyadmindata:/usr/src/phpmyadmin:ro
      depends_on:
        - mysql
        - phpmyadmin
  
  
    # Database
    mysql:
      image: mysql:5.7
      restart: always
      environment:
        MYSQL_ROOT_PASSWORD: root
        MYSQL_DATABASE: wordpress
        MYSQL_USER: wordpress
        MYSQL_PASSWORD: wordpress
      volumes:
        - mysql:/var/lib/mysql
  
  
    # phpmyadmin
    phpmyadmin:
      image: phpmyadmin/phpmyadmin:5-fpm-alpine
      restart: always
      environment:
        PMA_HOST: mysql
        MYSQL_ROOT_PASSWORD: root
      volumes:
        - phpmyadmindata:/usr/src/phpmyadmin
      depends_on:
        - mysql
  
    #wordpress1
    wordpress1:
      build: ./.docker/dockerfiles/wordpress1
      restart: always
      environment:
        WORDPRESS_DB_HOST: mysql
        WORDPRESS_DB_NAME: wordpress
        WORDPRESS_DB_USER: wordpress
        WORDPRESS_DB_PASSWORD: wordpress
      volumes:
        - ./sites/wordpress1:/var/www/html/wordpress1
  
    #wordpress2
    wordpress2:
      build: ./.docker/dockerfiles/wordpress2
      restart: always
      environment:
        WORDPRESS_DB_HOST: mysql
        WORDPRESS_DB_NAME: wordpress2
        WORDPRESS_DB_USER: wordpress
        WORDPRESS_DB_PASSWORD: wordpress
      volumes:
        - ./sites/wordpress2:/var/www/html/wordpress2
  
  volumes:
    phpmyadmindata:
    mysql:
  </code></pre>
  <p>dockerfile for wordpress1:</p>
  <pre><code>FROM  wordpress:5.5.1-php7.4-fpm
  WORKDIR /var/www/html/wordpress1
  </code></pre>
  <p>dockerfile for wordpress2:</p>
  <pre><code>FROM  wordpress:5.5.1-php7.4-fpm
  WORKDIR /var/www/html/wordpress2
  </code></pre>
  <p>nginx.conf</p>
  <pre><code>server {
      listen 80;
      listen [::]:80;
  
      server_name wordpress1.test;
      root /var/www/html/wordpress1;
  
      index index.php;
    
      location = /favicon.ico {
          log_not_found off;
          access_log off;
      }
  
      location = /robots.txt {
          allow all;
          log_not_found off;
          access_log off;
      }
  
      location / {
          try_files $uri $uri/ /index.php?$args;
      }
  
      location ~ \.php$ {
          include fastcgi_params;
          fastcgi_intercept_errors on;
          fastcgi_pass wordpress1:9000;
          fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }
  
      location ~* \.(js|css|png|jpg|jpeg|gif|ico|woff|woff2)$ {
          expires max;
          log_not_found off;
      }
  }
  
  server {
      listen 80;
      listen [::]:80;
  
      server_name wordpress2.test;
      root /var/www/html/wordpress2;
  
      index index.php;
    
      location = /favicon.ico {
          log_not_found off;
          access_log off;
      }
  
      location = /robots.txt {
          allow all;
          log_not_found off;
          access_log off;
      }
  
      location / {
          try_files $uri $uri/ /index.php?$args;
      }
  
      location ~ \.php$ {
          include fastcgi_params;
          fastcgi_intercept_errors on;
          fastcgi_pass wordpress2:9000;
          fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }
  
      location ~* \.(js|css|png|jpg|jpeg|gif|ico|woff|woff2)$ {
          expires max;
          log_not_found off;
      }
  }
  </code></pre>
  <p>and my phpmyadmin.conf</p>
  <pre><code>server {
      listen      80;
      listen      [::]:80;
      server_name phpmyadmin.test;
      root        /usr/src/phpmyadmin;
      index       index.php;
  
      location ~* \.php$ {
          fastcgi_pass   phpmyadmin:9000;
          include        fastcgi_params;
          fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param  SCRIPT_NAME     $fastcgi_script_name;
      }
  }
  </code></pre>
  <p>So, domains: wordpress1.test and wordpress2.test are working well
  but when I go to phpmyadmin.test I get 403 error and I have no idea, why.
  Can you help me?</p>
  <p>BTW. Why I have to use build Dockerfiles insted of writes:
  image: wordpress:5.5.1-fpm</p>