Docker mariadb와 wordpress 연동 

- Docker Compose를 활용하여


Docker compose 파일

[vagrant@dcentos work]$ cat mariadb_wordpress.yaml
version: '3.9'
networks:
  webapps:
    driver: bridge
    ipam:
      config:
      - subnet: 172.30.0.0/16
services:
  mywordpress:
    image: wordpress
    ports:
    - "9000:80"
    volumes:
    - wordpressfiles:/var/www/html
    networks:
      webapps:
        ipv4_address: 172.30.0.10
    environment:
      WORDPRESS_DB_HOST: mydb
      WORDPRESS_DB_NAME: userdb
      WORDPRESS_DB_USER: user1
      WORDPRESS_DB_PASSWORD: userpass
 #   links:  (deprecated)
 #     - mydb:db
    depends_on:
    - mydb
  mydb:
    image: mariadb
    ports:
    - "9001:3306"
    networks:
      webapps:
        ipv4_address: 172.30.0.11
    environment:
    - MARIADB_ROOT_PASSWORD=mypass
    - MARIADB_USER=user1
    - MARIADB_PASSWORD=userpass
    - MARIADB_DATABASE=userdb
    volumes:
    - dbfiles:/var/lib/mariadb
volumes:
  dbfiles:
  wordpressfiles:

 

도커 컴포즈 적용

[vagrant@dcentos work]$ docker compose -f mariadb_wordpress.yaml up -d
[+] Running 31/31
 ✔ mywordpress 21 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled             44.1s
   ✔ e1caac4eb9d2 Already exists                                                     0.0s
   ✔ 8c386db9cb1d Pull complete                                                      7.8s
   ✔ bef1b237c949 Pull complete                                                     11.3s
   ✔ 56c66cb68b0f Pull complete                                                      9.0s
   ✔ 9c790c1c009d Pull complete                                                     18.7s
   ✔ e055748d0b38 Pull complete                                                     15.9s
   ✔ 5a9d72b3b895 Pull complete                                                     16.0s
   ✔ 98b90bb43484 Pull complete                                                     19.2s
   ✔ b0a0159e983e Pull complete                                                     17.9s
   ✔ 4a03c0d0f683 Pull complete                                                     20.9s
   ✔ 5cb1486f0b5a Pull complete                                                     21.2s
   ✔ 370828abc98a Pull complete                                                     21.2s
   ✔ a789e0a12acd Pull complete                                                     22.1s
   ✔ 30b6bf5f6eeb Pull complete                                                     24.0s
   ✔ cc0d5481a137 Pull complete                                                     23.8s
   ✔ f8966f941a57 Pull complete                                                     23.4s
   ✔ 83483f29ea4d Pull complete                                                     24.3s
   ✔ 371dfab62a96 Pull complete                                                     24.5s
   ✔ 3f4af3e34785 Pull complete                                                     25.4s
   ✔ ad3725d6d7c1 Pull complete                                                     25.0s
   ✔ 82c78f0e7ebc Pull complete                                                     25.3s
 ✔ mydb 8 layers [⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                                  27.0s
   ✔ 01007420e9b0 Pull complete                                                      1.5s
   ✔ 31505b2b3fb6 Pull complete                                                      0.7s
   ✔ 97328dbb4b34 Pull complete                                                      1.1s
   ✔ 15d22565a968 Pull complete                                                      6.6s
   ✔ a150d2776ac9 Pull complete                                                      6.4s
   ✔ 5b0eb1c11437 Pull complete                                                      9.4s
   ✔ 11ffc9dfe027 Pull complete                                                      7.1s
   ✔ 51f9c9c328e6 Pull complete                                                      7.4s
[+] Running 2/3
 ⠋ Volume "work_wordpressfiles"  Created                                             2.0s
 ✔ Container work-mydb-1         Started                                             1.5s
 ✔ Container work-mywordpress-1  Started                                             1.3s

 

결과 확인

 

시간이 오래걸릴 것이라 생각했는데, 너무 간단했다...

+ Recent posts