Docker官方文档:https://docs.docker.com/samples/wordpress/

[root@docker ~]# mkdir my_wordpress/	# 创建文件夹
[root@docker ~]# cd my_wordpress/
[root@docker my_wordpress]# vi docker-compose.yaml		# 编写yaml文件
[root@docker my_wordpress]# cat docker-compose.yaml
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
    volumes:
      - wordpress_data:/var/www/html
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
volumes:
  db_data: {}
  wordpress_data: {}
[root@docker my_wordpress]# docker-compose up -d	# 运行
Creating network "my_wordpress_default" with the default driver
Creating volume "my_wordpress_db_data" with default driver
Creating volume "my_wordpress_wordpress_data" with default driver
Pulling db (mysql:5.7)...
5.7: Pulling from library/mysql
b380bbd43752: Pull complete
f23cbf2ecc5d: Pull complete
30cfc6c29c0a: Pull complete
b38609286cbe: Pull complete
8211d9e66cd6: Pull complete
2313f9eeca4a: Pull complete
7eb487d00da0: Pull complete
a71aacf913e7: Pull complete
393153c555df: Pull complete
06628e2290d7: Pull complete
ff2ab8dac9ac: Pull complete
Digest: sha256:2db8bfd2656b51ded5d938abcded8d32ec6181a9eae8dfc7ddf87a656ef97e97
Status: Downloaded newer image for mysql:5.7
Creating my_wordpress_db_1 ... done
Creating my_wordpress_wordpress_1 ... done
[root@docker my_wordpress]# docker ps	# 查看
CONTAINER ID   IMAGE              COMMAND                  CREATED              STATUS              PORTS                                         NAMES
bc4c072050bb   wordpress:latest   "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:8000->80/tcp, :::8000->80/tcp         my_wordpress_wordpress_1
d00f41b1eb49   mysql:5.7          "docker-entrypoint.s…"   About a minute ago   Up About a minute   3306/tcp, 33060/tcp                           my_wordpress_db_1
74ac7c819b66   wordpress          "docker-entrypoint.s…"   22 minutes ago       Up 22 minutes       0.0.0.0:1080->80/tcp, :::1080->80/tcp         OLDwp
e6b2d4ba4266   mysql:5.6          "docker-entrypoint.s…"   22 minutes ago       Up 22 minutes       0.0.0.0:33306->3306/tcp, :::33306->3306/tcp   OLDMysql

然后访问 :http:localhost:8000 就可以看到WordPress的安装界面了

# 用到的命令
mkdir my_wordpress/
cd my_wordpress/
vi docker-compose.yml
docker-compose up -d
docker ps
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐