Deploy MySQL and Wordpress under Docker
Check the current system version. Docker requires that CentOS must be at least 64 bit 7 version:
1. [ root@localhost ~]# cat /etc/redhat-release
2. CentOS Linux release 7.6.1810 (Core)
Check the kernel version. Docker supports kernel version 3.10 or above:
1. [ root@localhost ~]# uname -r
2. 3.10.0-957.el7.x86_64
Install Docker
1. [ root@localhost ~]# yum install -y docker
In order to speed up the download of Docker, we usually download from domestic image sites. Modify the mirror server
Open Profile
1. [ root@localhost ~]# cd /etc/docker
2. [ root@localhost docker]# vi daemon.json
To modify the content of the configuration file, select the AliCloud image site here:
1. {
2. "registry-mirrors": [" //6xacs6l2.mirror.aliyuncs.com "]
3. }
Start Docker service
1. [ root@localhost docker]# systemctl start docker.service
View the installed Docker version
1. [ root@localhost docker]# docker -v
2. Docker version 1.13.1, build 7f2769b/1.13.1
View the existing image (the new system image is empty)
1. [ root@localhost docker]# d ocker images
2. REPOSITORY TAG IMAGE ID CREATED SIZE
Search all images related to wordpress
1. [ root@localhost docker]# docker search wordpress
2. INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
3. docker.io docker.io/wordpress The WordPress rich content management syst... 3068 [OK]
4. docker.io docker.io/bitnami/wordpress Bitnami Docker Image for WordPress 116 [OK]
5. docker.io docker.io/tutum/wordpress Out-of-the-box WordPress docker image 35
6. docker.io docker.io/appcontainers/wordpress Centos/Debian Based Cust... 34 [OK]
7. docker.io docker.io/aveltens/wordpress-backup Easily backup and restor... 16 [OK]
8. docker.io docker.io/centurylink/wordpress WordPress image with MySQL removed. 14 [OK]
9. docker.io docker.io/arm32v7/wordpress The WordPress rich content management syst... ten
10. docker.io docker.io/appsvcorg/wordpress-alpine-php This is a WordPress Docker ... seven
11. docker.io docker.io/bitnami/wordpress-nginx Bitnami Docker Image for WordPress with NGINX 7 [OK]
Search for more than 5 records of "good stars" (the use of this parameter has been abolished and is not recommended)
1. [ root@localhost docker]# docker search wordpress -s 5
2. Flag --stars has been deprecated, use --filter=stars=3 instead
3. INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
4. docker.io docker.io/wordpress The WordPress rich content management syst... 3068 [OK]
5. docker.io docker.io/bitnami/wordpress Bitnami Docker Image for WordPress 116 [OK]
6. docker.io docker.io/tutum/wordpress Out-of-the-box WordPress docker image 35
7. docker.io docker.io/appcontainers/wordpress Centos/Debian Based ... 34 [OK]
8. docker.io docker.io/aveltens/wordpress-backup Easily backup and... 16 [OK]
9. docker.io docker.io/centurylink/wordpress WordPress image with MySQL removed. 14 [OK]
10. docker.io docker.io/arm32v7/wordpress The WordPress rich content management syst... ten
11. docker.io docker.io/appsvcorg/wordpress-alpine-php This is a WordPress Doc... seven
12. docker.io docker.io/bitnami/wordpress-nginx Bitnami Docker Image for WordPress with NGINX 7 [OK]
13. docker.io docker.io/dalareo/wordpress-ldap WordPress images with LDAP support automat... 6 [OK]
You can also use the latest parameters to filter and search for images with more than 100 stars:
1. [ root@localhost docker]# docker search wordpress --filter=stars=100
2. INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
3. docker.io docker.io/wordpress The WordPress rich content management syst... 3068 [OK]
4. docker.io docker.io/bitnami/wordpress Bitnami Docker Image for WordPress 116 [OK]
Pull the first latest version of wordpress
1. [ root@localhost docker]# docker pull wordpress
2. 。。。。。
3. 7e4ee285d305: Pull complete
4. Digest: sha256:6566a68d0c613304aa11255d98aba6e29c5fa8cd8497064639343956a4c7d2b1
5. Status: Downloaded newer image for docker.io/wordpress:latest
Pull the latest version of MySQL
1. [ root@localhost docker]# docker pull mysql
2. Using default tag: latest
3. Trying to pull repository docker.io/library/mysql ...
4. latest: Pulling from docker.io/library/
5. 。。。。。。。
6. Digest: sha256:01cf53f2538aa805bda591d83f107c394adca8d31f98eacd3654e282dada3193
7. Status: Downloaded newer image for docker.io/mysql:latest
View the current container list. Two image files we pulled have appeared:
1. [ root@localhost docker]# docker images
2. REPOSITORY TAG IMAGE ID CREATED SIZE
3. docker.io/wordpress latest 5040cbf30a44 2 days ago 502 MB
4. docker.io/mysql latest 62a9f311b99c 3 days ago 445 MB
5. [ root@localhost docker]#
Create and run MySQL container
1. [ root@localhost /]# docker run -d --privileged=true -p 3306:3306 --name wpmysql -v /data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=1111 mysql
2. cd13f4311f8e14511eba7d124a0a3a17a4ee553ccdfb4b45770535396c035256
3. [ root@localhost /]#
docker run -d
--Privileged=true enables the root in the container to have real root permissions
-P 3306:3306 Port mapping between host and container
--Name wpmysql Name the container
-V/data/mysql:/var/lib/mysql Mount MySQL to the local host
-E MYSQL_ROOT_PASSWORD=1111 Set the password of root user of MySQL database
mysql
Check the container operation. You can see the newly running MySQL container
1. [ root@localhost /]# docker ps
2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3. cd13f4311f8e mysql "docker-entrypoint..." 2 minutes ago Up About a minute 0.0.0.0:3306->3306/tcp, 33060/tcp wpmysql
4. [ root@localhost /]#
Create and run a WordPress container
1. [ root@localhost /]# docker run -d --name mywp -e WORDPRESS_DB_HOST=mysql -e WORDPRESS_DB_PASSWORD=1111 -p 80:80 --link wpmysql:mysql wordpress
2. 32ad7252ec8e7d0b3fd6abd8a8c4883f2cccdb4480f2994c14ee05b7b8f2dc76
docker run -d
--Name mywp Set container name
-E WORDPRESS_DB_PASSWORD=1111 Set the password to access the database
-P 80:80 Port mapping between host and container
--Link wpmysql: mysql connects to the mysq container
wordpress
View the currently running container list
1. [ root@localhost /]# docker ps
2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3. 32ad7252ec8e wordpress "docker-entrypoint..." 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp mywp
4. cd13f4311f8e mysql "docker-entrypoint..." 12 minutes ago Up 12 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp wpmysql
View the current IP address
1. [ root@localhost /]# ifconfig
2. ens33: flags=4163mtu 1500
3. inet 192.168.1.33 netmask 255.255.255.0 broadcast 192.168.1.255
4. inet6 fe80::e1b8:d032:218:5143 prefixlen 64 scopeid 0x20
5. ether 00:0c:29:2f:e3:aa txqueuelen 1000 (Ethernet)
6. RX packets 493392 bytes 712587368 (679.5 MiB)
7. RX errors 0 dropped 0 overruns 0 frame 0
8. TX packets 303935 bytes 22880279 (21.8 MiB)
9. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Open browser access address:
1. //192.168.1.33/wp-admin/install.php
Stop the MySQL container:
1. [ root@localhost mysql]# docker stop wpmysql wpmysql
Delete mysql container:
1. [ root@localhost mysql]# docker rm wpmysql wpmysql