[Amateur remarks] Build multiple WordPress on AWS using Docker Compose

1.First of all

I built WordPress with EC2, EBS, and MySQL using the AWS free frame, but it is a remarks column when I verified the construction with more efficient Docker Compose. ** Working environment: SSH (ec2-user) is connected to AWS for verification. ** **

2_1. Install docker.

sudo yum install  -y docker

Check the version of docker.

docker -v
Docker version 19.03.13-ce, build 4484c46

Run the docker service.

sudo service docker start

2_2. Install docker compose.

I referred to the following site.   https://docs.docker.jp/compose/install.html#linux Check the release page of the Compose repository on GitHub.   https://github.com/docker/compose/releases Install version 1.27.4.

sudo curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

Grant execution authority.

sudo chmod +x /usr/local/bin/docker-compose

Check the version of docker compose.

sudo /usr/local/bin/docker-compose -version
docker-compose version 1.27.4, build 40524192

3_1. Build WordPress using Docker Compose.

I referred to the following site.

Create a local environment where WordPress works using Docker Compose  https://codeaid.jp/blog/docker-wp/

3_2. Create a working folder.

mkdir docker_wp
cd docker_wp

3_3. Create an operating environment file (docker-compose.yml).

** Remarks: We will build a total of 3 sites, 2 WordPress sites and 1 phpMyAdmin site. ** **

nano docker-compose.yml

docker-compose.yml


version: '3.3'

services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root-pass

  wordpress1:
    depends_on:
      - db
    image: wordpress:latest
    volumes:
      - ./wp1:/var/www/html
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: root-pass
      WORDPRESS_DB_NAME: wp1-db

  wordpress2:
    depends_on:
      - db
    image: wordpress:latest
    volumes:
      - ./wp2:/var/www/html
    ports:
      - "8010:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: root-pass
      WORDPRESS_DB_NAME: wp2-db

  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    environment:
      PMA_HOST: db
    restart: always
    ports:
      - "8080:80"

volumes:
    db_data: {}

** Remarks: Host name, user name, password, database name, ports, etc. are optional. ** **

** Note: If you are connecting remotely, change the user (ec2-user → ssm-user). ** **

sudo su ssm-user

3_3. Execute the following command.

sudo /usr/local/bin/docker-compose up -d
Creating network "docker_wp_default" with the default driver
Creating volume "docker_wp_db_data" with default driver
Pulling db (mysql:5.7)...
5.7: Pulling from library/mysql
6ec7b7d162b2: Pull complete
fedd960d3481: Pull complete
7ab947313861: Pull complete
64f92f19e638: Pull complete
3e80b17bff96: Pull complete
014e976799f9: Pull complete
59ae84fee1b3: Pull complete
7d1da2a18e2e: Pull complete
301a28b700b9: Pull complete
529dc8dbeaf3: Pull complete
bc9d021dc13f: Pull complete
Digest: sha256:c3a567d3e3ad8b05dfce401ed08f0f6bf3f3b64cc17694979d5f2e5d78e10173
Status: Downloaded newer image for mysql:5.7
Pulling wordpress1 (wordpress:latest)...
latest: Pulling from library/wordpress
6ec7b7d162b2: Already exists
db606474d60c: Pull complete
afb30f0cd8e0: Pull complete
3bb2e8051594: Pull complete
4c761b44e2cc: Pull complete
c2199db96575: Pull complete
1b9a9381eea8: Pull complete
50450ffc67ee: Pull complete
4d1e5a768e83: Pull complete
5e8be0d1df16: Pull complete
7a6395859d40: Pull complete
7306499d3dce: Pull complete
fa6f0ba15ac6: Pull complete
308a9ead128f: Pull complete
2db781a8732e: Pull complete
63d3161e9e46: Pull complete
a08dd591ed8a: Pull complete
931a26282f2a: Pull complete
f5c6b405e809: Pull complete
caf2bb847f73: Pull complete
Digest: sha256:dadd8e9c2ef6dc2fe146cbc5f2edc0ed8ae1026ae252b52f25791be4d7d16600
Status: Downloaded newer image for wordpress:latest
Pulling phpmyadmin (phpmyadmin/phpmyadmin:)...
latest: Pulling from phpmyadmin/phpmyadmin
bb79b6b2107f: Pull complete
80f7a64e4b25: Pull complete
da391f3e81f0: Pull complete
8199ae3052e1: Pull complete
284fd0f314b2: Pull complete
f38db365cd8a: Pull complete
1416a501db13: Pull complete
1a45b5b978cd: Pull complete
c662caa8d2ec: Pull complete
2db216a7247d: Pull complete
d23772456121: Pull complete
3c068acf6c51: Pull complete
2980002e0c52: Pull complete
fa017dfc3023: Pull complete
81d3fce49de7: Pull complete
b6e4d8bc5eb9: Pull complete
f905c868a579: Pull complete
23e62ab5144c: Pull complete
Digest: sha256:44e37f6738cb7f5c4203def3b41ee45281286f6b2026826f309d1ab58efe12cb
Status: Downloaded newer image for phpmyadmin/phpmyadmin:latest
Creating docker_wp_db_1 ... done
Creating docker_wp_wordpress1_1 ... done
Creating docker_wp_wordpress2_1 ... done
Creating docker_wp_phpmyadmin_1 ... done

3_4. Check the status of the container.

sudo /usr/local/bin/docker-compose ps
         Name                       Command               State          Ports        
--------------------------------------------------------------------------------------
docker_wp_db_1           docker-entrypoint.sh mysqld      Up      3306/tcp, 33060/tcp 
docker_wp_phpmyadmin_1   /docker-entrypoint.sh apac ...   Up      0.0.0.0:8080->80/tcp
docker_wp_wordpress1_1   docker-entrypoint.sh apach ...   Up      0.0.0.0:8000->80/tcp
docker_wp_wordpress2_1   docker-entrypoint.sh apach ...   Up      0.0.0.0:8010->80/tcp

4_1. Confirm that WordPress and phpMyAdmin have started.

Check the AWS port. aws-port.jpg

Check each site from the browser. kidou.jpg

http://Babrick IP:8000 → WordPress 1
http://Babrick IP:8010 → WordPress 2
http://Babrick IP:8080 → phpMyAdmin

4_2. Perform the WordPress installation.

After setting the WordPress user etc., a trouble occurred after executing the installation. The command in the terminal became unresponsive, so on the AWS EC2 dashboard When I checked the instance, the CPU usage was 99%. When I checked it again after a while, the CPU usage rate had dropped, so I was able to avoid the trouble by restarting the instance. cpu-moniter.jpg

To log in to docker_wp_wordpress1_1, execute the following command.

sudo docker exec -i -t docker_wp_wordpress1_1 /bin/bash

Remarks: docker images can be confirmed at the following site. https://github.com/docker-library/official-images/tree/master/library

Postscript

At work, I used VirtualBox etc. to build an environment such as Windows 7 and Wndows 10 in a virtual environment and verified Windows Update etc. We were able to verify that Docker has no OS and can efficiently build multiple sites. In this verification, I was able to realize the work efficiency of Docker Compose.

Recommended Posts

[Amateur remarks] Build multiple WordPress on AWS using Docker Compose
WordPress with Docker Compose on CentOS 8
Build an environment with Docker on AWS
Easily build Redmine on Windows using WSL2 and Docker
Deploy laravel using docker on EC2 on AWS ① (Create EC2 instance)
[Docker] Build an Apache container on EC2 using dockerfile
Build WordPress environment with Docker (Local) and AWS (Production)
[Amateur remarks] CentOS 8 was installed on Raspberry Pi 4 8G, and Wordpress was built using Docker-Compose.
Creating a docker host on AWS using Docker Machine (personal memorandum)
Deploy laravel using docker on EC2 on AWS ② (Elastic IP acquisition-linking)
Deploy laravel using docker on EC2 on AWS ④ (git clone ~ deploy, migration)
Install docker on AWS EC2
multi-project docker build using jib
Deploy laravel using docker on EC2 on AWS ③ (SSH connection ~ Docke-compose installation)
Install Docker on AWS Ubunt 20.04 LTS
Try using Redmine on Mac docker
Use Docker Compose on Windows 10 Home
To beginners launching Docker on AWS
Build a Minecraft server on AWS
Run the AWS CLI on Docker
Build Rails environment with Docker Compose
Build Clang x VSCode on Docker (1)
Using Docker on Windows10 Home WSL2
Build Unity development environment on docker
How to build CloudStack using Docker
How to build a Ruby on Rails environment using Docker (for Docker beginners)
Build Maven repository on AWS S3 service
Deployed using Docker + Rails + AWS (EC2 + RDS)
Build a Maven repository on AWS S3
Build Java 8 development environment on AWS Cloud9
Quick build maven project using maven docker container
Build an authentication proxy server using Docker
Build a Wordpress development environment with Docker
[AWS] [docker] Internet connection failed during docker build
Build Redmine code reading environment on Docker
Send an email using JavaMail on AWS
Try using Kong + Konga with Docker Compose.
Try the Docker environment on AWS ECS
Build an Ultra96v2 development environment on Docker 1
Building an environment for WordPress, MySQL and phpMyAdmin with Docker Compose on EC2