Docker-compose部署wordpress

Posted 一夜入秋

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker-compose部署wordpress相关的知识,希望对你有一定的参考价值。

1、Docker-compose部署wordpress

1.1、规划目录

在生产中会有很多项目,为了区分都会提前建好相关的目录。

root@node1:~# mkdir -pv /data/wordpress/web,mysql
mkdir: created directory /data
mkdir: created directory /data/wordpress
mkdir: created directory /data/wordpress/web
mkdir: created directory /data/wordpress/mysql

1.2、获取镜像

Docker-compose部署wordpress的话是会使用到wordpress和MySQL镜像,镜像可以实现下载好,在生产环境是会根据需求来打镜像的。

root@node1:~# docker pull wordpress
root@node1:~# docker pull mysql:5.7.39
root@node1:~# docker images 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.7.39              3147495b3a5c        3 weeks ago         431MB
wordpress           latest              c3c92cc3dcb1        7 months ago        616MB


1.3、编写docker-compose.yml文件

root@node1:~# cd /data/wordpress/
root@node1:/data/wordpress# vim docker-compose.yml
root@node1:/data/wordpress# cat docker-compose.yml
root@node1:/data/wordpress# cat docker-compose.yml
version: "3"
services:
  db:
    image: mysql:5.7.39
    command:
      - --default_authentication_plugin=mysql_native_password
      - --character-set-server=utf8
      - --collation-server=utf8_unicode_ci
    volumes:
      - /data/wordpress/mysql:/var/lib/mysql
    ports:
      - "3306:3306"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: wm521314
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress123
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "80:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress123
    volumes:
      - /data/wordpress/web:/var/www/html
#编辑完后检查一下文件的语法
root@node1:/data/wordpress# docker-compose config -q    #检查一下是否有错误,没有错误就不会输出任何内容

1.4、启动并查看容器的数据

root@node1:/data/wordpress# docker-compose up -d
Creating network "wordpress_default" with the default driver
Creating wordpress_db_1 ... done
Creating wordpress_wordpress_1 ... done
root@node1:/data/wordpress# docker-compose ps
        Name                       Command               State                 Ports              
--------------------------------------------------------------------------------------------------
wordpress_db_1          docker-entrypoint.sh --def ...   Up      0.0.0.0:3306->3306/tcp, 33060/tcp
wordpress_wordpress_1   docker-entrypoint.sh apach ...   Up      0.0.0.0:80->80/tcp               
root@node1:/data/wordpress# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
4b633e3aa6a1        wordpress:latest    "docker-entrypoint.s…"   35 seconds ago      Up 34 seconds       0.0.0.0:80->80/tcp                  wordpress_wordpress_1
d9946cacedff        mysql:5.7.39        "docker-entrypoint.s…"   36 seconds ago      Up 35 seconds       0.0.0.0:3306->3306/tcp, 33060/tcp   wordpress_db_1


1.5、wordpress的站点初始化








以上是关于Docker-compose部署wordpress的主要内容,如果未能解决你的问题,请参考以下文章

用docker-compose部署wordpress博客系统

Centos7.4下用Docker-Compose部署WordPress

docker-compose wordpress mysql连接被拒绝

畅享docker-compose之旅及编排wordpress报错解决

idea 使用docker插件部署docker-compose失败?

Docker Compose创建Wordpress应用