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. ** **
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
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
I referred to the following site.
Create a local environment where WordPress works using Docker Compose https://codeaid.jp/blog/docker-wp/
mkdir docker_wp
cd docker_wp
** 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
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
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
Check the AWS port.
Check each site from the browser.
http://Babrick IP:8000 → WordPress 1
http://Babrick IP:8010 → WordPress 2
http://Babrick IP:8080 → phpMyAdmin
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.
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
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