Docker下部署MySQL和Wordpress
检查当前系统版本,Docker要求CentOS必须是64位7版本以上才可以:
1. [root@localhost ~]#cat /etc/redhat-release
2. CentOS Linux release 7.6.1810 (Core)
检查内核版本,Docker支持内核3.10版本以上:
1. [root@localhost ~]#uname -r
2. 3.10.0-957.el7.x86_64
安装Docker
1. [root@localhost ~]#yum install -y docker
为了加快Docker的下载速度,我们一般从国内镜像站点下载。修改镜像服务器
打开配置文件
1. [root@localhost ~]#cd /etc/docker
2. [root@localhost docker]#vi daemon.json
修改配置文件内容,此处选择阿里云的镜像站点:
1. {
2.
3. }
启动Docker服务
1. [root@localhost docker]#systemctl start docker.service
查看安装的Docker版本
1. [root@localhost docker]#docker -v
2. Docker version 1.13.1, build 7f2769b/1.13.1
查看当前已有的镜像(新建系统镜像为空)
1. [root@localhost docker]# docker images
2. REPOSITORY TAG IMAGE ID CREATED SIZE
搜索全部与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… 10
10. docker.io docker.io/appsvcorg/wordpress-alpine-php This is a WordPress Docker … 7
11. docker.io docker.io/bitnami/wordpress-nginx Bitnami Docker Image for WordPress with NGINX 7 [OK]
搜索获得“好评 stars”超过的5个的记录(这个参数的用法已经被废止,不建议使用了)
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… 10
11. docker.io docker.io/appsvcorg/wordpress-alpine-php This is a WordPress Doc… 7
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]
也可以使用最新的参数进行过滤搜索,搜索星数量超过100的镜像:
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]
拉取第一个最新版本的wordpriss
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
拉取最新版的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
查看当前容器列表,已经出现我们拉取的两个镜像文件了:
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]#
创建并运行MySQL容器
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 使container内的root拥有真正的root权限
-p 3306:3306 将主机和容器之间进行端口映射
–name wpmysql 为容器起名
-v /data/mysql:/var/lib/mysql 将mysql挂载到本地主机
-e MYSQL_ROOT_PASSWORD=1111 设置mysql数据库root用户的密码
mysql
检查容器运行情况,可以看到新运行的mysql容器
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 /]#
创建并运行WordPress容器
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 设置容器名称
-e WORDPRESS_DB_PASSWORD=1111 设置访问数据库的密码
-p 80:80 在主机和容器间进行端口映射
–link wpmysql:mysql 连接到mysq容器
wordpress
查看当前运行的容器列表
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
查看当前IP
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
php
停止mysql容器:
1. [root@localhost mysql]# docker stop wpmysql wpmysql
删除mysql容器:
1. [root@localhost mysql]# docker rm wpmysql wpmysql
☉vip会员全站90%资源均可以免费下载,有问题可以加入技术QQ群一起交流学习。
☉本站提供的网站源码,都是做好测试好发布的,均可放心使用。
☉如有其他问题,请加网站客服QQ(906875572)进行交流,QQ交流群(877945832)。
☉资源与文章搜集于网络整理,如若本站内容侵犯了原著者的合法权益,可联系我们进行处理906875572@qq.com。