Docker – Docker로 WordPress Blog 만들기

설치한 Docker 환경에서 WordPress를 만들어 보자.

먼저 WordPress를 실행하려면 Apache (또는 NGINX) + PHP + MariaDB (mySQL)을 먼저 설치하고 WordPress를 설치 한뒤 설정을 하는 방법으로 WordPress를 구축 했었다.

DB는 계속 사용해야 하는 부분으로 MariaDB(mySQL)만 분리해서 준비되어 있다면 Docker 이미지를 이용하면 나머지 작업은 간단하게 할 수 있다. 당근 이 2개 모두 Docker를 이용하여 실행 하는 것이 가능 하다.

1. 프로젝트 디렉토리 만들기

$ mkdir my-wordpress
$ cd my-wordpress

2. docker-compose 만들기

docker-compose.yml 파일을 만들고 WordPress 와 mySQL 인스턴스 데이터를 현대 디렉토리를 사용하도록 구성 한다.

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
    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: {}

3. container 구동 시키기

root@dck:~/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
b4d181a07f80: Pull complete
a462b60610f5: Pull complete
578fafb77ab8: Pull complete
524046006037: Pull complete
d0cbe54c8855: Pull complete
aa18e05cc46d: Pull complete
32ca814c833f: Pull complete
52645b4af634: Pull complete
bca6a5b14385: Pull complete
309f36297c75: Pull complete
7d75cacde0f8: Pull complete
Digest: sha256:1a2f9cd257e75cc80e9118b303d1648366bc2049101449bf2c8d82b022ea86b7
Status: Downloaded newer image for mysql:5.7
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordpress
b4d181a07f80: Already exists
78b85dd8f014: Pull complete
8589b26a90be: Pull complete
f5af5d641946: Pull complete
614ec6f0b8d6: Pull complete
12b28f3797fb: Pull complete
96bcb7d2e6b0: Pull complete
09a46dfaa772: Pull complete
1a85b508a14e: Pull complete
c6fd9c89235a: Pull complete
40b955b2d455: Pull complete
fda03b9af7e2: Pull complete
570ea029c915: Pull complete
a3f5858f9e8b: Pull complete
e563e5b2630b: Pull complete
10499c79181c: Pull complete
7180626436df: Pull complete
72df520dac82: Pull complete
ed2d407056b5: Pull complete
7224b35f0930: Pull complete
7bf10a169530: Pull complete
Digest: sha256:0a2b70369b24a45802e33d5870638bac3c7f289dfcb0d0a9b6e9990c0a217c27
Status: Downloaded newer image for wordpress:latest
Creating my-wordpress_db_1 ... done
Creating my-wordpress_wordpress_1 ... done
root@dck:~/my-wordpress#

4. 실행된 컨테이너 확인

root@dck:~/my-wordpress# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                  NAMES
b48106898dcc        wordpress:latest    "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:8000->80/tcp   my-wordpress_wordpress_1
b7dbb8ebb7dc        mysql:5.7           "docker-entrypoint.s…"   About a minute ago   Up About a minute   3306/tcp, 33060/tcp    my-wordpress_db_1
root@dck:~/my-wordpress#
root@dck:~/my-wordpress# docker container ls -as
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES                      SIZE
b48106898dcc        wordpress:latest    "docker-entrypoint.s…"   2 minutes ago       Up 2 minutes        0.0.0.0:8000->80/tcp   my-wordpress_wordpress_1   2B (virtual 551MB)
b7dbb8ebb7dc        mysql:5.7           "docker-entrypoint.s…"   2 minutes ago       Up 2 minutes        3306/tcp, 33060/tcp    my-wordpress_db_1          4B (virtual 447MB)
root@dck:~/my-wordpress#

5. WordPress 접속 및 설정하기

브라우저로 docker container를 설치한 vm에 접속하면 WordPress 설정 화면을 만날수 있다.
이제 부터는 이전에 WordPress 설정을 한것 처럼 진행을 하면 된다.

Leave a Reply

Your email address will not be published. Required fields are marked *