Word press 설치

docker-compose 파일 만들기

요구사항

  • Nextcloud Nginx Proxy + HTTPS(letsencrypt)  container 활용
  • VIRTUAL_HOST=blg.igotoo.pw
  • LETSENCRYPT_HOST=blg.igotoo.pw
  • LETSENCRYPT_EMAIL=igotoo@gmail.com
  • Wordpress 파일 및 DB 데이터 Host volume 사용
  • Html 파일 :  /media/usbhdd1/wordpress/var/www/html
  • DB data 파일 : /media/usbhdd1/wordpress/var/lib/mysql

참고파일

wordpress 원본파일 : 참고 > Install WordPress with Docker Compose

version: '3.3'

services:
   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     volumes:
       - wordpress_files:/var/www/html
     ports:
       - "80:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: my_wordpress_db_password

   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: my_db_root_password
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: my_wordpress_db_password
volumes:
    wordpress_files:
    db_data:

webty docker-compose.yml

version: '3'
services:
 webtty:
  container_name:  webtty
  image: test2/wetty
  restart: always
  environment:
   - VIRTUAL_HOST=wty.igotoo.pw
   - LETSENCRYPT_HOST=wty.igotoo.pw
   - LETSENCRYPT_EMAIL=igotoo@gmail.com
networks:
  default:
   external:
     name: apache_proxy-tier

nextcloud docker-compose.yml

version: '3'
services:
  db:
    image: mariadb
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: always
    volumes:
      - /media/usbhdd1/nextcloud/var/lib/mysql:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=jbsk1107!
    env_file:
      - db.env
  redis:
    image: redis
    restart: always
  app:
    build: ./app
    restart: always
    volumes:
      - /media/usbhdd1/nextcloud/var/www/html:/var/www/html
      - /media/usbhdd1/shares/plex-movie:/media/plex
    environment:
      - VIRTUAL_HOST=cld.igotoo.pw
      - LETSENCRYPT_HOST=cld.igotoo.pw
      - LETSENCRYPT_EMAIL=igotoo@gmail.com
      - MYSQL_HOST=db
    env_file:
      - db.env
    depends_on:
      - db
      - redis
    networks:
      - proxy-tier
      - default
  cron:
    build: ./app
    restart: always
    volumes:
      - /media/usbhdd1/nextcloud/var/www/html:/var/www/html
    entrypoint: /cron.sh
    depends_on:
      - db
      - redis
       cron:
    build: ./app
    restart: always
    volumes:
      - /media/usbhdd1/nextcloud/var/www/html:/var/www/html
    entrypoint: /cron.sh
    depends_on:
      - db
      - redis
  proxy:
    build: ./proxy
    restart: always
    ports:
      - 80:80
      - 443:443
    labels:
      com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: "true"
    volumes:
      - certs:/etc/nginx/certs:ro
      - vhost.d:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - /var/run/docker.sock:/tmp/docker.sock:ro
    networks:
      - proxy-tier
  letsencrypt-companion:
    image: jrcs/letsencrypt-nginx-proxy-companion
    restart: always
    volumes:
      - certs:/etc/nginx/certs
      - vhost.d:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - proxy-tier
    depends_on:
      - proxy
volumes:
  certs:
  vhost.d:
  html:
networks:
  proxy-tier:

yaml 파일 작성

version: '3.3'

services:
   wordpress:
     depends_on:
       - db
     image: wordpress:latest
      container_name: wdpress
     volumes:
       -/media/usbhdd1/wordpress/var/www/html:/var/www/html
     restart: always
     environment:
       VIRTUAL_HOST: blg.igotoo.pw
       LETSENCRYPT_HOST: blg.igotoo.pw
       LETSENCRYPT_EMAIL: igotoo@gmail.com
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wdpress
       WORDPRESS_DB_PASSWORD: wdp1107!

   db:
     image: mysql:5.7
     volumes:
       - /media/usbhdd1/wordpress/var/lib/mysql:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: my_db_root_password
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wdpress
       MYSQL_PASSWORD: wdp1107!
networks:
  default:
   external:
     name: apache_proxy-tier

restart: always 서버 부팅시에 Docker compose가 자동으로 서비스를  기동 시킴

You do not need to manually start your containers if you reboot your Linode, because the option restart: always was assigned to your services in your docker-compose.yml file. This option tells Docker Compose to automatically start your services when the server boots.

컨테이너 생성

디렉토리 만들기

기동

  • wdpress 및 wdpress_db_1 생성/기동
bori@BorilikeGame:/media/usbhdd1/wordpress$ docker-compose up -d
Pulling db (mysql:5.7)...
5.7: Pulling from library/mysql
802b00ed6f79: Already exists
30f19a05b898: Pull complete
3e43303be5e9: Pull complete
94b281824ae2: Pull complete
51eb397095b1: Pull complete
54567da6fdf0: Pull complete
bc57ddb85cce: Pull complete
c7c0a9c25d8a: Pull complete
cce6c47ac3fc: Pull complete
499b9c7376c8: Pull complete
6c5e08e005ea: Pull complete
Digest: sha256:1d8f471c7e2929ee1e2bfbc1d16fc8afccd2e070afed24805487e726ce601a6d
Status: Downloaded newer image for mysql:5.7
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordpress
802b00ed6f79: Already exists
59f5a5a895f8: Already exists
6898b2dbcfeb: Already exists
8e0903aaa47e: Already exists
2961af1e196a: Already exists
71f7016f79a0: Already exists
5e1a48e5719c: Already exists
7ae5291984f3: Already exists
725b65166f31: Already exists
e90b121f9520: Pull complete
b5a272809bbd: Pull complete
f045f3ae0e2b: Pull complete
7f51c9ea2d8e: Pull complete
5aa9d0ed164a: Pull complete
8eea44e2bfc7: Pull complete
48918885026e: Pull complete
8ac3e8ada01a: Pull complete
d3da911b920f: Pull complete
94c7e0af5b20: Pull complete
99e40bb3c01a: Pull complete
Digest: sha256:07d30db02654f352b46a071f772e01c9489fa6fd6124290bebd1d6ff9779f505
Status: Downloaded newer image for wordpress:latest
Creating wordpress_db_1 ... done
Creating wdpress        ... done
bori@BorilikeGame:/media/usbhdd1/wordpress$ docker ps
CONTAINER ID        IMAGE                                    COMMAND                  CREATED              STATUS                  PORTS                                      NAMES
2a7b1feec965        wordpress:latest                         "docker-entrypoint.s…"   About a minute ago   Up 30 seconds           80/tcp                                     wdpress
fda466845124        mysql:5.7                                "docker-entrypoint.s…"   About a minute ago   Up About a minute       3306/tcp, 33060/tcp                        wordpress_db_1

유지보수

서비스 중지

  • 중지 및 컨테이너 삭제 시  - 컨테이너만 삭제 되고 DB 데이터와 파일은 보존 됨
cd /media/usbhdd1/wordpress/
docker-compose down
When a Docker container is stopped, it is also deleted; this is how Docker is designed to work. However, your WordPress files and data will be preserved, as the docker-compose.yml file was configured to create persistent named volumes for that data.
If you want to remove this data and start over with your WordPress site, you can add the --volumesflag to the previous command. This will permanently delete the WordPress posts and customizations you’ve made so far.
docker-compose down --volumes
  • 단순 서비스만 중지
docker-compose stop

업데이트

  • 컨테이너 삭제 후 최신 버전으로 이미지 재 생성 후 기동
docker-compose down
docker-compose pull && docker-compose up -d

참고 Site

Quickstart: Compose and WordPress | Docker Documentation

Install WordPress with Docker Compose

GitHub - docker-library/wordpress: Docker Official Image packaging for WordPress

igotoo

igotoo