[GCP] Google cloud Docker-compose wordpress 구성

[GCP] Google cloud Docker-compose wordpress 구성

 

도메인만 있으면 1년간 무료로 쓸수 있는 Google cloud 를 이용하여 WordPress 를 구성하여 사용하는것도 좋을거 같습니다. 🙂

기존 생성했던 VM 을 사용 하기 때문에 최초로 만든 vm 이미지에서 수정을 합니다.

Compute Engine -> VM 인스턴스 -> 인스턴스 이름 클릭 후 수정을 클릭합니다.

 

초소형(공유vCPU 1개) -> 소형 (공유 vCPU 1개) 로 변경후 저장을 클릭합니다.

 

VM 인스턴스를 시행후 SSH로 접속을 합니다.

 

docker 설치

test@ubuntu-trusty-1:~$ curl -s https://get.docker.com/ | sudo sh
test@ubuntu-trusty-1:~$ sudo usermod -aG docker test

터미널을 재접속 합니다.

 

docker 설치 확인

test@ubuntu-trusty-1:~$ docker --version
Docker version 18.02.0-ce, build fc4de44
test@ubuntu-trusty-1:~$

 

docker-compose 설치

test@ubuntu-trusty-1:~$ sudo curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0   2762      0 --:--:-- --:--:-- --:--:--  2766
100 8288k  100 8288k    0     0  7366k      0  0:00:01  0:00:01 --:--:-- 17.6M
test@ubuntu-trusty-1:~$ sudo chmod +x /usr/local/bin/docker-compose
test@ubuntu-trusty-1:~$ docker-compose --version
docker-compose version 1.19.0, build 9e633ef
test@ubuntu-trusty-1:~$

 

Nginx-proxy container

test@ubuntu-trusty-1:~$ mkdir -p web-service/nginx-proxy
test@ubuntu-trusty-1:~$ cd web-service/nginx-proxy/
test@ubuntu-trusty-1:~/web-service/nginx-proxy$ vi docker-compose.yml
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

 

Nginx-proxy container 실행

test@ubuntu-trusty-1:~/web-service/nginx-proxy$ docker network create nginx-proxy
6e66bd966be8c43541585319e0516c3350d5b1d852789ca4efd93ee9ef446589
test@ubuntu-trusty-1:~/web-service/nginx-proxy$ docker-compose up -d --build
test@ubuntu-trusty-1:~/web-service/nginx-proxy$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                NAMES
b4bbe5ac5015        jwilder/nginx-proxy   "/app/docker-entrypo…"   4 seconds ago       Up 3 seconds        0.0.0.0:80->80/tcp   nginx-proxy
test@ubuntu-trusty-1:~/web-service/nginx-proxy$

 

 

WordPress container

blog docker-compose.yml 파일 생성

test@ubuntu-trusty-1:~$ mkdir -p web-service/blog
test@ubuntu-trusty-1:~$ cd web-service/blog/
test@ubuntu-trusty-1:~/web-service/blog$ mkdir web-data
test@ubuntu-trusty-1:~/web-service/blog$ mkdir db-data
test@ubuntu-trusty-1:~/web-service/blog$ 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: blog.crois.net
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: test1234
     container_name: wp_blog

networks:
  default:
    external:
      name: nginx-proxy

 

WordPress container 실행

test@ubuntu-trusty-1:~$ cd web-service/blog/
test@ubuntu-trusty-1:~/web-service/blog$ docker-compose up -d --build
~중략
실행확인
test@ubuntu-trusty-1:~/web-service/blog$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED              STATUS              PORTS                NAMES
7d728447bde6        mariadb               "docker-entrypoint.s…"   8 seconds ago        Up 7 seconds        3306/tcp             wp_blog_db
9415c6dd76e1        wordpress:latest      "docker-entrypoint.s…"   8 seconds ago        Up 7 seconds        80/tcp               wp_blog
b4bbe5ac5015        jwilder/nginx-proxy   "/app/docker-entrypo…"   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp   nginx-proxy
test@ubuntu-trusty-1:~/web-service/blog$

 

web browser 에서 http://blog.crois.net 을 연결 합니다.

수고 하셨습니다. 🙂

 

 

 

 

댓글 남기기