๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

์นดํ…Œ๊ณ ๋ฆฌ ์—†์Œ

[docker] compose.yml ํŒŒ์ผ ์ž‘์„ฑ

728x90
๋ฐ˜์‘ํ˜•

๐Ÿ”ต compose.yml ํŒŒ์ผ์ด๋ž€?

๋‹ค์ค‘ container Docker app ์„ ์ •์˜ํ•˜๊ณ  ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ๋„๊ตฌ์ด๋‹ค. docker build ๋ฅผ ํ•˜๊ฒŒ ๋˜๋ฉด ๋‹จ์ผ ํด๋”๋กœ app์„ ์„œ๋น„์Šค ํ•˜๊ฒŒ ๋˜๋Š”๋ฐ, docker-compose.yml ์€ ์—ฌ๋Ÿฌ ํด๋”์˜ ๋ณต์žกํ•œ app์„ ์‰ฝ๊ฒŒ ์‹คํ–‰, ๊ด€๋ฆฌ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค.

๐ŸŸข ์ž‘์„ฑ์˜ˆ์‹œ

version: "3.9"

services:
  express_server:
    build: ./server
    ports:
      - "5000:5000"
    depends_on:
      - db
    environment:
      - MONGODB_URI=mongodb://db:27017/color99b

  db:
    image: mongo:latest
    ports:
      - "27017:27017"

  next_server:
    build: ./servertest
    ports:
      - "3000:3000"
    environment:
      - EXPRESS_SERVER_URL=http://express_server:5000

๐ŸŸฃ ์ž‘์„ฑ ์˜ˆ์‹œ ์„ค๋ช…

- version : Docker compose ํŒŒ์ผ ํ˜•์‹์˜ ๋ฒ„์ „.

- services : app์„ ๊ตฌ์„ฑํ•˜๋Š” ์„œ๋น„์Šค(container) ๋ฅผ ์ •์˜ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋œ๋‹ค. (express, next, db 3๊ฐœ์˜ ๊ตฌ์„ฑ)

- express : backEnd ์„œ๋ฒ„
 - build : ์œ„ service ์— ๋Œ€ํ•œ Dockerfile ์ด ํฌํ•จ๋œ directory์˜ ๊ฒฝ๋กœ
 - ports : ์ปจํ…Œ์ด๋„ˆ์— ์˜ํ•ด ๋…ธ์ถœ๋  ํฌํŠธ, ํ˜ธ์ŠคํŠธ์˜ ํฌํŠธ : ๊ธฐํ˜ธ๋กœ mapping
 - depends_on : ์œ„ service ๊ฐ€ ์˜์กดํ•˜๋Š” ์„œ๋น„์Šค๋ฅผ ์ง€์ •ํ•œ๋‹ค.
 - environment : ์ปจํ…Œ์ด๋„ˆ์— ์ „๋‹ฌํ•  ํ™˜๊ฒฝ๋ณ€์ˆ˜. mongodb์— ์—ฐ๊ฒฐํ•˜๊ธฐ์œ„ํ•ด uri๋ฅผ ์ „๋‹ฌํ•œ๋‹ค.

- db : database
 - image: mongo์˜ docker image ๋ฒ„์ „

- next : front ์„œ๋ฒ„
 - ํ•˜์œ„ ํ•ญ๋ชฉ์€ ์œ„ express ์™€ ๊ฐ™์Œ. 

๐ŸŸ  ์‹คํ–‰

docker-compose up

 

728x90
๋ฐ˜์‘ํ˜•


Calendar
ยซ   2025/04   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Archives
Visits
Today
Yesterday