Как запустить WordPress в Docker

Устанавливаем Docker. Распаковываем wp
Создаем структуру:

db Dockerfile:

FROM mysql:8.0
COPY wordpress.sql docker-entrypoint-initdb.d/wordpress.sql

nginx/default.conf

server {
  listen 80;
  listen [::]:80;

  root /var/www/html;
  index index.php;

  access_log /var/log/nginx/site-access.log;
  error_log /var/log/nginx/site-error.log;

  location / {
    try_files $uri $uri/ /index.php?$args;
  }

  location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass wordpress:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
  }
}

контейнер php не используем, он будет входить в контейнер WordPress

В папке в c wp создаем файл docker-compose.yml с содержимым:


version: '3'
services:
  nginx:
    image: nginx:latest
    container_name: nginx
    ports:
      - "80:80"
    volumes:
      - .:/var/www/html
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
      - ./docker/nginx/log:/var/log/nginx/
    command:
      - chown -R www-data:www-data html
    links:
      - wordpress
  mysql:
    container_name: mysql
    build: ./docker/db
    ports:
      - "3306:3306"
    environment:
      - MYSQL_DATABASE=wordpress
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_USER=mysql
      - MYSQL_PASSWORD=mysql

  wordpress:
    image: wordpress:php7.4-fpm-alpine
    volumes:
      - .:/var/www/html
    depends_on:
      - mysql
    environment:
      WORDPRESS_DB_HOST: mysql
      MYSQL_ROOT_PASSWORD: root
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: mysql
      WORDPRESS_DB_PASSWORD: mysql
      WORDPRESS_TABLE_PREFIX: rwp_
    command: php-fpm -R # Allow running FPM as root
    links:
      - mysql
    restart: always
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin
    ports:
      - 8090:80
    links:
      - mysql:db
volumes:
  .:
    external: true

Пишем в командной строке

docker-compose up

— Поднять контейнеры образа
Теперь сайт доступен по адресу http://localhost/ 

В Docker Desktop: