💭

WordPressのローカル環境をdockerで構築

2024/01/12に公開

はじめに

WordPressのプロジェクトをdockerを使って構築。
phpmyadminSearch Replace DBにもアクセスできるようになります。

ディレクトリ構造

├── httpdocs
├── docker-compose.yml
├── .env

httpdocs下にWordPressのプロジェクトを設置。

docker-compose.ymlの作成

version: "3"
services:
  app:
    container_name: ${CONTAINER_NAME}_app
    image: wordpress
    ports:
      - 8080:80
    volumes:
      - "./httpdocs:/var/www/html"
    networks:
      - wordpressindocker_default
  db:
    container_name: ${CONTAINER_NAME}_db
    image: mysql:5.7
    volumes:
      - db-data:/var/lib/mysql
    networks:
      - wordpressindocker_default
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
  phpmyadmin:
    container_name: ${CONTAINER_NAME}_phpmyadmin
    image: phpmyadmin/phpmyadmin
    ports:
      - 8888:80
    networks:
      - wordpressindocker_default
    volumes:
      - ./phpmyadmin/phpmyadmin-misc.ini:/usr/local/etc/php/conf.d/phpmyadmin-misc.ini

  srdb:
    container_name: ${CONTAINER_NAME}_srdb
    image: kgaut/docker-search-replace-db
    ports:
      - 9090:80
    environment:
      DB_HOST: "db"
      DB_USER: "wordpress"
      DB_PASS: "wordpress"
      DB_NAME: "wordpress"
    depends_on:
    - db
    networks:
      - wordpressindocker_default

volumes:
  db-data:

networks:
  wordpressindocker_default:

同階層に.envファイルを作ります。

CONTAINER_NAME = xxx

dockerの起動

docker-compose up -d

localhost:8080
localhost:8888 phpmyadmin
localhost:10000 Search Replace DB

以上

Discussion