Quick Start: Compose and WordPress Set up and run WordPress using Docker Compose.
CentOS Linux release 8.2.2004 (Core) Docker version 19.03.13, build 4484c46d9d
Install Docker Compose On Linux, download the Docker Compose binary from the release page of the Compose repository on GitHub.
# curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
<blockquote> % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 651 100 651 0 0 10850 0 --:--:-- --:--:-- --:--:-- 10850
100 11.6M 100 11.6M 0 0 4932k 0 0:00:02 0:00:02 --:--:-- 8008k</blockquote>
```# chmod +x /usr/local/bin/docker-compose```
As of today (2020-11-06), the Compose repository on GitHub was 1.27.4, so I have specified 1.27.4.
# Project definition
Create a project directory and change to the project directory.
<blockquote> If the directory is my_wordpress, for example, it will be as follows. </ blockquote>
```# cd my_wordpress```
# Generate docker-compose.yml file
Generate a docker-compose.yml file.
version: '3'
services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: somewordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress
wordpress: depends_on: - db image: wordpress:latest ports: - "8000:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress volumes: db_data:
It is better to specify the version for mysql as it may stumble on the version of mysql.
# Building a project
Run docker-compose up -d on the project directory
```# docker-compose up -d```
<blockquote>Creating network "my_wordpress_default" with the default driver
Creating volume "my_wordpress_db_data" with default driver
Pulling db (mysql:5.7)...
5.7: Pulling from library/mysql
bb79b6b2107f: Pull complete
49e22f6fb9f7: Pull complete
842b1255668c: Pull complete
9f48d1f43000: Pull complete
c693f0615bce: Pull complete
8a621b9dbed2: Pull complete
0807d32aef13: Pull complete
f15d42f48bd9: Pull complete
098ceecc0c8d: Pull complete
b6fead9737bc: Pull complete
351d223d3d76: Pull complete
Digest: sha256:4d2b34e99c14edb99cdd95ddad4d9aa7ea3f2c4405ff0c3509a29dc40bcb10ef
Status: Downloaded newer image for mysql:5.7
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordpress
bb79b6b2107f: Already exists
80f7a64e4b25: Pull complete
da391f3e81f0: Pull complete
8199ae3052e1: Pull complete
284fd0f314b2: Pull complete
f38db365cd8a: Pull complete
1416a501db13: Pull complete
ab2461348ce4: Pull complete
085f6c1f7281: Pull complete
d5b4ad1cc063: Pull complete
791ee5a4264d: Pull complete
b3544511e544: Pull complete
abf41ac6b39b: Pull complete
b6439c866cc6: Pull complete
2990e7a8854f: Pull complete
14660d5f95a2: Pull complete
b8b0371e52ce: Pull complete
14b4eaf6e3f6: Pull complete
36bf819b74a1: Pull complete
1dcde27b5fe8: Pull complete
Digest: sha256:0364d2f6476244fc73fd521a092a083f4259edf6f56811cd45bb187de4034fdc
Status: Downloaded newer image for wordpress:latest
Creating my_wordpress_db_1 ... done
Creating my_wordpress_wordpress_1 ... done</blockquote>
# Launching WordPress on a web browser ... failed
Access http: // localhost: 8000 from your web browser
<a href="https://ebios10.up.seesaa.net/image/2020-11-06_174718.png " target="_blank"><img border="0" alt="2020-11-06_174718.png " src="https://ebios10.up.seesaa.net/image/2020-11-06_174718-thumbnail2.png " width="640" height="187"></a>
I got a WordPress "database connection establishment error" saying "Error establishing a database connection".
# Causes of WordPress startup failure on web browser
The cause is that the host OS is CentOS8. It seems that the name cannot be resolved.
Either ① or ② is the solution.
(1) Set the firewall for each device (not recommended)
(2) Set the IP masquerade (recommended)
In case of (1), use the nmcli command to set the firewall for wordpress and mysql on a device-by-device basis. In particular
```# nmcli```
<blockquote> enp1s0: profile 1 from connected
"Realtek RTL8111/8168/8411"
ethernet (r8169), D8:CB:8A:12:98:1F, hw, mtu 1500
ip4 default, ip6 default
inet4 192.168.0.6/24
route4 192.168.0.0/24
route4 0.0.0.0/0
inet6 240f:37:7aa3:1:4cd8:6a49:f36c:d35/64
inet6 fe80::3c4d:980f:ab77:80e3/64
route6 240f:37:7aa3:1::/64
route6 ::/0
route6 fe80::/64
route6 ff00::/8
br-4aef7bc26106: From connected br-4aef7bc26106
"br-4aef7bc26106"
bridge, 02:42:65:2F:2F:33, sw, mtu 1500
inet4 192.168.96.1/20
route4 192.168.96.0/20
inet6 fe80::42:65ff:fe2f:2f33/64
route6 fe80::/64
route6 ff00::/8
docker0: connected to docker0
"docker0"
bridge, 02:42:F2:CB:91:F3, sw, mtu 1500
inet4 172.17.0.1/16
route4 172.17.0.0/16
inet6 fe80::42:f2ff:fecb:91f3/64
route6 fe80::/64</blockquote>
```# firewall-cmd --permanent --zone=trusted --change-interface=docker0```
success
```# firewall-cmd --permanent --zone=trusted --change-interface=br-4aef7bc26106```
success
```# firewall-cmd --reload```
success
In this case, the br- device will generate a different ID each time, so I don't recommend it because you need to set it every time you run docker-compose up -d.
In case of (2), simply set the IP masquerade once. Recommended.
```# firewall-cmd --add-masquerade --permanent```
success
```#firewall-cmd --reload```
success
# Launching WordPress on a web browser ... successful
Access http: // localhost: 8000 from your web browser
<a href="https://ebios10.up.seesaa.net/image/2020-11-06_211730.png " target="_blank"><img border="0" alt="2020-11-06_211730.png " src="https://ebios10.up.seesaa.net/image/2020-11-06_211730-thumbnail2.png " width="640" height="492"></a>
WordPress started successfully.
After failing
```# docker-compose down --volumes```
After shutting down and cleaning up with
```# docker-compose up -d```
Is re-executed with. In addition, it is necessary to wait for a while because it cannot be accessed by DB construction for a while after startup.
# The addictive place is CentOS 8
Normally, it's easy if you follow the procedure of "<a href="https://docs.docker.jp/compose/wordpress.html#id7" target="_blank"> Quick Start: Compose and WordPress </a>" It succeeded until WordPress started, but this time I got hooked on the place where the host OS is CentOS 8. I think it was an example of having to disclose what you are using for the host OS when you are in trouble.
Recommended Posts