使用docker compose一键部署WordPress博客的方法
作者:xybDIY
这篇文章主要介绍了docker-compose一键部署WordPress博客,本文分步骤给大家讲解的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
1、创建wordpress项目目录
[root@docker ~]# mkdir wordpress [root@docker ~]# cd wordpress/ [root@docker wordpress]#
2、创建docker-compose.yml配置文件
[root@docker wordpress]# touch docker-compose.yml [root@docker wordpress]# vim docker-compose.yml [root@docker wordpress]# cat docker-compose.yml version: "3.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 - wordpress_data:/var/www/html ports: - "8000:80" WORDPRESS_DB_HOST: db WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress WORDPRESS_DB_NAME: wordpress volumes: db_data: {} wordpress_data: {} [root@docker wordpress]#
3、一键启动wordpress项目
docker-compose up -d
命令运行执行过程如下所示
[root@docker wordpress]# docker-compose up -d Creating network "wordpress_default" with the default driver Creating volume "wordpress_db_data" with default driver Creating volume "wordpress_wordpress_data" with default driver Pulling wordpress (wordpress:latest)... latest: Pulling from library/wordpress a2abf6c4d29d: Pull complete c5608244554d: Pull complete 2d07066487a0: Pull complete 1b6dfaf1958c: Pull complete 32c5e6a60073: Pull complete 90cf855b27cc: Pull complete 8b0f1068c586: Pull complete 5355461305e8: Pull complete ad1eec592342: Pull complete e03fbc76cb78: Pull complete 1f5796e48b39: Pull complete 72fbe8e1d4e7: Pull complete 96edece66175: Pull complete 5f46f0743de2: Pull complete c9f9671a5e1f: Pull complete 3f543dcd35b1: Pull complete c88e21a0c2a0: Pull complete 964b4457a910: Pull complete 0d55fb9a64ef: Pull complete fb009ff7c567: Pull complete 4f058a67a50d: Pull complete Digest: sha256:fc33b796b04162a0db2e9ea9b4c361a07058b21597b1317ad9ab3ea4593de241 Status: Downloaded newer image for wordpress:latest Creating wordpress_db_1 ... done Creating wordpress_wordpress_1 ... done
4、查看相关信息参数
查看正在运行的容器
[root@docker wordpress]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 74dde54efbe0 wordpress:latest "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:8000->80/tcp, :::8000->80/tcp wordpress_wordpress_1 f22bc03ae9ca mysql:5.7 "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp, 33060/tcp wordpress_db_1 [root@docker wordpress]#
查看wordpress镜像
[root@docker wordpress]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE wordpress latest c3c92cc3dcb1 4 months ago 616MB mysql 5.7 c20987f18b13 4 months ago 448MB
查看wordpress镜像详细信息参数
[root@docker wordpress]# docker image inspect wordpress [ { "Id": "sha256:c3c92cc3dcb1a903fed0374a837f38d716ae104d0e4c9705bddb53a76419534d", "RepoTags": [ "wordpress:latest" ], "RepoDigests": [ "wordpress@sha256:fc33b796b04162a0db2e9ea9b4c361a07058b21597b1317ad9ab3ea4593de241" ], "Parent": "", "Comment": "", "Created": "2021-12-22T12:22:44.907734362Z", "Container": "76e81f08668906b548f73ef1272100f6fa94ce50eb13bcb9701750958ccb9f7c", "ContainerConfig": { "Hostname": "76e81f086689", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "80/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "PHPIZE_DEPS=autoconf \t\tdpkg-dev \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkg-config \t\tre2c", "PHP_INI_DIR=/usr/local/etc/php", "APACHE_CONFDIR=/etc/apache2", "APACHE_ENVVARS=/etc/apache2/envvars", "PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64", "PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64", "PHP_LDFLAGS=-Wl,-O1 -pie", "GPG_KEYS=42670A7FE4D0441C8E4632349E4FDC074A4EF02D 5A52880781F755608BF815FC910DEB46F53EA312", "PHP_VERSION=7.4.27", "PHP_URL=https://www.php.net/distributions/php-7.4.27.tar.xz", "PHP_ASC_URL=https://www.php.net/distributions/php-7.4.27.tar.xz.asc", "PHP_SHA256=3f8b937310f155822752229c2c2feb8cc2621e25a728e7b94d0d74c128c43d0c" ], "Cmd": [ "/bin/sh", "-c", "#(nop) ", "CMD [\"apache2-foreground\"]" ], "Image": "sha256:946e01a0332f0a94ab8098875adfccd45de7853714478cdc675c160bc190fa95", "Volumes": { "/var/www/html": {} }, "WorkingDir": "/var/www/html", "Entrypoint": [ "docker-entrypoint.sh" ], "OnBuild": null, "Labels": {}, "StopSignal": "SIGWINCH" }, "DockerVersion": "20.10.7", "Author": "", "Config": { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "80/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "PHPIZE_DEPS=autoconf \t\tdpkg-dev \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkg-config \t\tre2c", "PHP_INI_DIR=/usr/local/etc/php", "APACHE_CONFDIR=/etc/apache2", "APACHE_ENVVARS=/etc/apache2/envvars", "PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64", "PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64", "PHP_LDFLAGS=-Wl,-O1 -pie", "GPG_KEYS=42670A7FE4D0441C8E4632349E4FDC074A4EF02D 5A52880781F755608BF815FC910DEB46F53EA312", "PHP_VERSION=7.4.27", "PHP_URL=https://www.php.net/distributions/php-7.4.27.tar.xz", "PHP_ASC_URL=https://www.php.net/distributions/php-7.4.27.tar.xz.asc", "PHP_SHA256=3f8b937310f155822752229c2c2feb8cc2621e25a728e7b94d0d74c128c43d0c" ], "Cmd": [ "apache2-foreground" ], "Image": "sha256:946e01a0332f0a94ab8098875adfccd45de7853714478cdc675c160bc190fa95", "Volumes": { "/var/www/html": {} }, "WorkingDir": "/var/www/html", "Entrypoint": [ "docker-entrypoint.sh" ], "OnBuild": null, "Labels": null, "StopSignal": "SIGWINCH" }, "Architecture": "amd64", "Os": "linux", "Size": 616019481, "VirtualSize": 616019481, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/10e7ab6038414fc88332b2eae4cfb14dda92edab7760b81e2dcbae95be47eaeb/diff:/var/lib/docker/overlay2/2884bfc529cfa8044e82537076f6b15f0cb003b549b952668e276039bdceef9a/diff:/var/lib/docker/overlay2/e8e3a23fdb1faa46be8380d0476acd576a49a97befb0a018c65db5addac6c3a3/diff:/var/lib/docker/overlay2/aa9b79869b43445fbdc6a31f3f6bd4d902bbff010a9a6e109856e9ceea4bf4ad/diff:/var/lib/docker/overlay2/c139cd93e615ec61b79e69c94f4319f797b485b76d48f00ce9faa77c195fc452/diff:/var/lib/docker/overlay2/136d4761234aca9c82ca233753f250a46169f5401e51518811614ded12ebefa4/diff:/var/lib/docker/overlay2/f78ed7733ca7b5d5ef0f02ac04f98eb8c1e22f37a93a9f0278b7f3108c6f3a48/diff:/var/lib/docker/overlay2/6cdeaa8faad2381a61ae21c133a6bdcdb61cf558cf6e89fc9e8db7c352301d1f/diff:/var/lib/docker/overlay2/0b4cea44728b2d74bf39fb69f9ccb6402e2117ebf4d54b8f2d14653d032ba12f/diff:/var/lib/docker/overlay2/d27e9fcb57f79408927a6e2910086bad36d88291a601e877f028513840399bc3/diff:/var/lib/docker/overlay2/2f2b18318c209c0184b5766670808285e0545c1e68a1658efb511636d1033f28/diff:/var/lib/docker/overlay2/ed9a87da9254ad473c92a820295874ab67d88c492647ff1bb78e160b05c7dcc7/diff:/var/lib/docker/overlay2/dd7b9486ac80666eefc319070f00aeb1f26f1df1dda5301f57ab4c24ba2771b3/diff:/var/lib/docker/overlay2/0450b509c683bec9e8bad207d87a7eb505d69f086961be46e0c8df868ab1144e/diff:/var/lib/docker/overlay2/d55a71f8bab352884cdce71228f76973a7734a3a0a8a3facba3f496059346ba4/diff:/var/lib/docker/overlay2/2fe09d1aa764b041a3f27dd4399390e14b3fb64b4464fd5b26afef2a3a56f4bf/diff:/var/lib/docker/overlay2/87ba02c078abca0b51ee759547e0313ed0dbe26581ce034742ba938bfea5bf88/diff:/var/lib/docker/overlay2/d7ff4ef14ccaae7407682309049ce6158f389e4bd205b68886ac758461733422/diff:/var/lib/docker/overlay2/2e2cb15add20c5ba711c5273f1fdddb7f1a54d488952a8816d5b470f583b07b7/diff:/var/lib/docker/overlay2/b806a2064e4e38e04f61fc73eddb216c2de6d65ff83772fe4eb05a63887b0b00/diff", "MergedDir": "/var/lib/docker/overlay2/ae8ebfb3d264d1e16727a7b1ae2e717969a8907c5749ad6523f399b909b3bb06/merged", "UpperDir": "/var/lib/docker/overlay2/ae8ebfb3d264d1e16727a7b1ae2e717969a8907c5749ad6523f399b909b3bb06/diff", "WorkDir": "/var/lib/docker/overlay2/ae8ebfb3d264d1e16727a7b1ae2e717969a8907c5749ad6523f399b909b3bb06/work" }, "Name": "overlay2" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:2edcec3590a4ec7f40cf0743c15d78fb39d8326bc029073b41ef9727da6c851f", "sha256:2a3138346faa8ee4b6576fcbb2c6fee83f0bbe068d9bba5e3319929fcd8c7ada", "sha256:0fdfbbf7aebd824633c30eeb27764703e6542240276c77be96a361a0317a1048", "sha256:ee0ca96d307e2b44287feb00422347eca7e232623cd296836bc4fa667a5afb66", "sha256:6e4300c6b758e4eb09040760786bb6f80a2e9292a99473e04b5437ba49f223a5", "sha256:5649286863133a7dc1abc7e4df13abfb2ba9d9873f8b279e74321a4e4317cfcd", "sha256:6c39776a30a0f2123685eb293379f7662f41947245a4bb436612d12ac500e84d", "sha256:23946094ff3f63e854aa094f023dcb277ffec1ab69d8799c0ac0105d1f611bc1", "sha256:b299cffd87cbd3caccb7cc2d1bddf236693585f041fe9fde441d9a82feb20ff8", "sha256:56543a169be6589b8408e4aaa230e529870dafedd5cf191ced84a9ba13cd60b4", "sha256:55d40777afe64bab763a7d744513ddb93a29b3f5802ca0575fe03c0a8ed67dc9", "sha256:7446d340e7f8da0e738b0a1a9fb6a1fe906e7e9d238447a44519e6d1e225d30f", "sha256:10dfb82106c4667a9e465437331fe459e6d50369832b38d0a88b862f1cfa71e7", "sha256:d390f2d56bd85a24191a667840c3836506f73d69522ab793dcb41965f269f9a9", "sha256:0d79fe9ffe74abce48ccf46c394e162115ec5a40cf57e993f8c7f3041e1205f4", "sha256:4793c0a2ad02c5fab0556045d0a182c69218d0a8e892f32047b0666e472b406b", "sha256:a4e2d002482e345abd2cb9e92f0d86fd5af455752be758bc9b3c80c55ecacbce", "sha256:f0287c40b0d61bcb53f04716fab390a45d96af7f9e7104bce13793edc4a516c7", "sha256:98b68a8435741330255aa4c24df32f82b356e44fe0089dc288e3d74ef6722ac5", "sha256:8f1b90d2be40e2da876dc34793e4938ea1591b2f54e396f931564ee07ad1d585", "sha256:c7ae1aefcc695d00e45dd1cd3517ac92893f07c0915261609d044636e6d2c86b" ] }, "Metadata": { "LastTagTime": "0001-01-01T00:00:00Z" } } ]
查看wordpress的网络信息
[root@docker wordpress]# docker network ls NETWORK ID NAME DRIVER SCOPE 6da4ea82dc8f bridge bridge local 6122e04c63b8 composetest_default bridge local 2fff17891e10 host host local 7aa928301028 mynet bridge local e09cdd0344b3 none null local 6e65d674deba redis bridge local 366cc0a1f57b wordpress_default bridge local 531566df42e7 xybdiy_workpress_default bridge local
查看wordpress容器的网络详细信息
[root@docker wordpress]# docker network inspect 366cc0a1f57b [ { "Name": "wordpress_default", "Id": "366cc0a1f57b7b23ddfb5e46e3f6a48040294e61fc66a4065a2bfe163b48681c", "Created": "2022-04-23T22:58:30.173133699+08:00", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.20.0.0/16", "Gateway": "172.20.0.1" } ] }, "Internal": false, "Attachable": true, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, "Containers": { "74dde54efbe05c5e7a5f57c174272d9ab68f333b358f517e0763eea9040c9a47": { "Name": "wordpress_wordpress_1", "EndpointID": "919b186d0fb0d56026300450432091abcde8ebb411b5ae1db400297aa6f2cc1c", "MacAddress": "02:42:ac:14:00:03", "IPv4Address": "172.20.0.3/16", "IPv6Address": "" }, "f22bc03ae9ca55daa657a98a0e5f212b14bd3ca57c3244cd50e588d871b6b1f2": { "Name": "wordpress_db_1", "EndpointID": "01ba837f9dc58acd3fa90655c4cc5d0d1b639aaab10c1dc1aa1f81ca8f04a2c9", "MacAddress": "02:42:ac:14:00:02", "IPv4Address": "172.20.0.2/16", "IPv6Address": "" } }, "Options": {}, "Labels": { "com.docker.compose.network": "default", "com.docker.compose.project": "wordpress", "com.docker.compose.version": "1.25.0" } } ] [root@docker wordpress]#
5、配置wordpress
http://192.168.200.8:8000/wp-admin/install.php
1、选择语言版本信息。
2、配置相关信息。设置站点名、用户名、密码等。
3、安装完成。
4、使用用户名和密码登录wordpress。
5、登录完成,进入wordpress博客后台。
6、查看wordpress初始化网页界面。
至此,wordpress通过docker-compose一键安装部署完成。
到此这篇关于docker compose一键部署WordPress博客的文章就介绍到这了,更多相关docker compose一键部署WordPress博客内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!