天天看點

docker部署wordpress

docker-compose.yml檔案内容:

version: '2'
services:
   nginx:
      image: nginx:1.13.12
      container_name: nginx
      restart: always
      depends_on:
        - wordpress
      ports:
        - 80:80
      networks:
         extnetwork:
            ipv4_address: 172.19.0.100
      volumes:
        - '/app/nginx/nginx.conf:/etc/nginx/nginx.conf:ro'
        - '/app/nginx/conf.d:/etc/nginx/conf.d'

   mysql:
     image: mysql:5.7
     container_name: mysql
     volumes:
       - /app/mysql:/var/lib/mysql
     restart: always
     ports:
       - '3306:3306'
     networks:
         extnetwork:
            ipv4_address: 172.19.0.101
     environment:
       MYSQL_ROOT_PASSWORD: wordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: root
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - mysql
     image: wordpress:5.2.1
     container_name: wordpress
     ports:
       - '8080:80'
     restart: always
     networks:
         extnetwork:
            ipv4_address: 172.19.0.102
     volumes:
       - /app/wordpress:/var/www/html
     environment:
       WORDPRESS_DB_HOST: mysql:3306
       WORDPRESS_DB_NAME: wordpress
       WORDPRESS_DB_USER: root
       WORDPRESS_DB_PASSWORD: wordpress

networks:
   extnetwork:
      ipam:
         config:
         - subnet: 172.19.0.0/16
           gateway: 172.19.0.1
           

我們在docker-compose裡面配置了mysql的賬号,以及wordpress的連接配接池賬号

建立應用目錄

mkdir -p /app/nginx

mkdir -p /app/mysql

mkdir -p /app/wordpress

進入nginx目錄并建立配置檔案

這裡建立nginx主配置檔案

cd /app/nginx

touch nginx.conf

[email protected]:/app/nginx# cat nginx.conf 
user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    include /etc/nginx/conf.d/*.conf;
}
           

然後建立nginx子配置檔案

mkdir conf.d

touch conf.d/default.conf

[email protected]:/app/nginx/conf.d# cat default.conf 
server {
    listen 80;
    server_name localhost hechaojie.com;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_pass http://wordpress;
    }  
}
           

配置完成後執行:

docker-compose up -d

浏覽首頁就可以安裝wordpress了

http://hechaojie.com/

管理頁面位址

http://hechaojie.com/admin

繼續閱讀