[docker] docker-compose Nginx-proxy multi-wordpress site

nginx-proxy multi-wordpress site

 

Site:https://www.draw.io

Nginx-proxy 를 이용하여 여러대의 wordpress container 사용할수 있습니다.

Nginx-proxy container 는 jwilder/nginx-proxy image 를 이용합니다.

 

Github

test@docker-test:~$ git clone https://github.com/visualwork/Docker-test.git

/Docker-test/test05 에 있습니다. 🙂

 

Nginx-proxy docker-compose.yml 파일 생성

test@docker-test:~$ mkdir -p web-service/nginx-proxy
test@docker-test:~$ cd web-service/nginx-proxy/
test@docker-test:~/web-service/nginx-proxy$ vi docker-compose.yml
## notice ##  $ docker network create nginx-proxy
version: "3"

services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
    restart: always

networks:
  default:
    external:
      name: nginx-proxy

 

Docker network 생성

Nginx-proxy container 구동전 docker network create commnad 를 이용하여 docker network 를 생성해야 합니다.

test@docker-test:~/web-service/nginx-proxy$ docker network create nginx-proxy
a5955ea1067f169fd1849ecd4c959c83319183dcb39188ddffe125423f9e5322
test@docker-test:~/web-service/nginx-proxy$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
e64ced1895e7        bridge              bridge              local
a2b1f4b8cfba        host                host                local
a5955ea1067f        nginx-proxy         bridge              local
bb45871e893c        none                null                local
test@docker-test:~/web-service/nginx-proxy$

 

 

WordPress container

blog1 docker-compose.yml 파일 생성

container 사용시 db가 저장될 디렉토리와 web 이 저장될 디렉토리를 생성 합니다.

test@docker-test:~/web-service$ mkdir blog1
test@docker-test:~/web-service$ cd blog1/
test@docker-test:~/web-service/blog1$ mkdir web-data
test@docker-test:~/web-service/blog1$ mkdir db-data
test@docker-test:~/web-service/blog1$ tree
.
├── db-data
└── web-data

 

docker-compose 파일 생성

도메인의 경우 test.com 을 Test dns-server 로 미리 준비해 놓았습니다.

test@docker-test:~/web-service/blog1$ vi docker-compose.yml
version: "3"

services:
  db:
     image: mariadb
     volumes:
       - ./db-data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: test1234
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: test1234
     container_name: wp_blog_db

  wordpress:
     image: wordpress:latest
     expose:
       - 80
     restart: always
     volumes:
       - ./web-data:/var/www/html
     environment:
       VIRTUAL_HOST: blog1.test.com
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: test1234
     container_name: wp_blog

networks:
  default:
    external:
      name: nginx-proxy

VIRTUAL_HOST 부분에 도메인을 설정해 줍니다. ex) blog1.test.com

 

Nginx-proxy 와 blog Wordprss 컨테이너를 구동 합니다.

Nginx-proxy 컨테이너 실행

test@docker-test:~/web-service$ cd ..
test@docker-test:~$ cd web-service/nginx-proxy/
test@docker-test:~/web-service/nginx-proxy$ docker-compose up -d --build
Pulling nginx-proxy (jwilder/nginx-proxy:latest)...
latest: Pulling from jwilder/nginx-proxy
e7bb522d92ff: Pull complete
6edc05228666: Pull complete
cd866a17e81f: Pull complete
d9f2d6a1f8f6: Pull complete
e9c7e986c8c1: Pull complete
a51bcd518fd9: Pull complete
66df98413ed2: Pull complete
aff8c6473b42: Pull complete
1c91fd608be1: Pull complete
7319453a5fbe: Pull complete
Digest: sha256:41506b2095779e6e64f34e26ccba35cb3668ee56a735cd740ac8c183af583294
Status: Downloaded newer image for jwilder/nginx-proxy:latest
Creating nginx-proxy ... done
test@docker-test:~/web-service/nginx-proxy$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                NAMES
2b9135ebe937        jwilder/nginx-proxy   "/app/docker-entrypo…"   4 seconds ago       Up 3 seconds        0.0.0.0:80->80/tcp   nginx-proxy
test@docker-test:~/web-service/nginx-proxy$

이제부터 시스템의 모든 80 Port 의 경우 Nginx-proxy 에서 받아 들이게 됩니다.

 

blog1 컨테이너 실행

test@docker-test:~$ cd web-service/blog1/
test@docker-test:~/web-service/blog1$ docker-compose up -d --build
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordpress
8176e34d5d92: Pull complete
f6c81892adaa: Pull complete
c8125c73b868: Pull complete
5ef22f6299b6: Pull complete
8537460e9a8c: Pull complete
b837671b83f0: Pull complete
366ea9d8b411: Pull complete
c4dd539af472: Pull complete
445753fb3ee6: Pull complete
6811f6b5d500: Pull complete
2ca365cdc65d: Pull complete
c91023a57f04: Pull complete
dcf0735fda8a: Pull complete
6b23fdc3538b: Pull complete
2eed880b86fe: Pull complete
798b2e547e59: Pull complete
159be43511e4: Pull complete
b5605b08f665: Pull complete
20d8e9ec2764: Pull complete
Digest: sha256:670e4156377063df1a02f036354c52722de0348d46222ba30ef6a925c24cd46a
Status: Downloaded newer image for wordpress:latest
Pulling db (mariadb:latest)...
latest: Pulling from library/mariadb
4176fe04cefe: Pull complete
d1e86691d483: Pull complete
c3f621b14a80: Pull complete
7b3f1b17db07: Pull complete
add1151625d9: Pull complete
d40e879009a8: Pull complete
0f888e49f29b: Pull complete
bd51d7af1551: Pull complete
6cf37448a3b3: Pull complete
0519e00d29e5: Pull complete
8f83e3487101: Pull complete
Digest: sha256:d5f0bc88ba397233677ff75b7b1de693d5e84527ecf2b4f59adebf8d0bcac3c4
Status: Downloaded newer image for mariadb:latest
Creating wp_blog ... done
Creating wp_blog_db ...
test@docker-test:~/web-service/blog1$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                NAMES
e83e15350e05        wordpress:latest      "docker-entrypoint.s…"   4 seconds ago       Up 2 seconds        80/tcp               wp_blog
ce6d5afb2986        mariadb               "docker-entrypoint.s…"   4 seconds ago       Up 4 seconds        3306/tcp             wp_blog_db
2b9135ebe937        jwilder/nginx-proxy   "/app/docker-entrypo…"   3 minutes ago       Up 3 minutes        0.0.0.0:80->80/tcp   nginx-proxy
test@docker-test:~/web-service/blog1$

 

web browser  접속

http://blog1.test.com 으로 접속합니다.

blog1 컨테이너 구성이 끝났습니다. Wordprss 설정을 한후 blog2 컨테이너를 구성 합니다.

 

 

blog2 docker-compose.yml 파일 생성

test@docker-test:~$ cd web-service/
test@docker-test:~/web-service$ mkdir blog2
test@docker-test:~/web-service$ cd blog2
test@docker-test:~/web-service/blog2$ mkdir db-data
test@docker-test:~/web-service/blog2$ mkdir web-data
test@docker-test:~/web-service/blog2$ vi docker-compose.yml
version: "3"

services:
  db2:
     image: mariadb
     volumes:
       - ./db-data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: test1234
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: test1234
     container_name: wp_blog_db2

  wordpress2:
     image: wordpress:latest
     expose:
       - 80
     restart: always
     volumes:
       - ./web-data:/var/www/html
     environment:
       VIRTUAL_HOST: blog2.test.com
       WORDPRESS_DB_HOST: db2:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: test1234
     container_name: wp_blog2

networks:
  default:
    external:
      name: nginx-proxy

 

docker-compose.yml 파일 변경 사항

db -> db2

wp_blog_db ->  wp_blog_db2

wordpress -> wordpress2

VIRTUAL_HOST: blog2.test.com

WORDPRESS_DB_HOST: db2:3306

container_name: wp_blog2

 

blog2 컨테이너 실행

test@docker-test:~/web-service/blog2$ docker-compose up -d --build
Creating wp_blog2 ... done
Creating wp_blog2 ...
test@docker-test:~/web-service/blog2$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED              STATUS              PORTS                NAMES
468a1f13cee1        wordpress:latest      "docker-entrypoint.s…"   About a minute ago   Up About a minute   80/tcp               wp_blog2
39d91c742082        mariadb               "docker-entrypoint.s…"   About a minute ago   Up About a minute   3306/tcp             wp_blog_db2
fa9442409280        mariadb               "docker-entrypoint.s…"   9 minutes ago        Up 9 minutes        3306/tcp             wp_blog_db
416704fdb038        wordpress:latest      "docker-entrypoint.s…"   9 minutes ago        Up 9 minutes        80/tcp               wp_blog
2b9135ebe937        jwilder/nginx-proxy   "/app/docker-entrypo…"   21 minutes ago       Up 21 minutes       0.0.0.0:80->80/tcp   nginx-proxy
test@docker-test:~/web-service/blog2$

 

 

web browser  접속

http://blog2.test.com 으로 접속합니다.

 

 

 

댓글 남기기