compose.yml 파일에 서비스 별로 띄울 컨테이너들을 작성한다.
다수의 컨테이너를 관리하기 용이하다.
1. Docker Compose 로 MySQL, Redis 실행
1) compose.yml 파일 작성
- compose-practice/compose.yml
services:
my-db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: pwd123
volumes:
- ./mysql_data:/var/lib/mysql
ports:
- 3306:3306
my-cache-server:
image: redis
ports:
- 6379:6379
* 주의
YAML 문법에서 들여쓰기 중요!
2) compose 파일 실행
- Windows PowerShell
PS C:\Users\admin\compose-practice> docker compose up -d
[+] up 3/3
✔ Network compose-practice_default Created 0.0s
✔ Container compose-practice-my-cache-server-1 Started 0.6s
✔ Container compose-practice-my-db-1 Started 0.6s
What's next:
Filter, search, and stream logs from all your Compose services
in one place with Docker Desktop's Logs view. docker-desktop://dashboard/logs?appId=compose-practice
3) compose 실행 현황 확인
- Windows PowerShell
PS C:\Users\admin\compose-practice> docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
compose-practice-my-cache-server-1 redis "docker-entrypoint.s…" my-cache-server 43 seconds ago Up 41 seconds 0.0.0.0:6379->6379/tcp, [::]:6379->6379/tcp
compose-practice-my-db-1 mysql "docker-entrypoint.s…" my-db 43 seconds ago Up 41 seconds 0.0.0.0:3306->3306/tcp, [::]:3306->3306/tcp
PS C:\Users\admin\compose-practice> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
da7d57f45b94 redis "docker-entrypoint.s…" 47 seconds ago Up 46 seconds 0.0.0.0:6379->6379/tcp, [::]:6379->6379/tcp compose-practice-my-cache-server-1
f6e12bb40175 mysql "docker-entrypoint.s…" 47 seconds ago Up 46 seconds 0.0.0.0:3306->3306/tcp, [::]:3306->3306/tcp compose-practice-my-db-1
4) 컨테이너 로그 확인
- Windows PowerShell
PS C:\Users\admin\compose-practice> docker compose logs
my-cache-server-1 | Starting Redis Server
my-db-1 | 2026-06-01 13:20:10+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 9.7.0-1.el9 started.
my-cache-server-1 | 1:C 01 Jun 2026 13:20:10.475 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
my-cache-server-1 | 1:C 01 Jun 2026 13:20:10.476 * Redis version=8.6.3, bits=64, commit=00000000, modified=1, pid=1, just started
my-cache-server-1 | 1:C 01 Jun 2026 13:20:10.476 * Configuration loaded
my-db-1 | 2026-06-01 13:20:10+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
my-db-1 | 2026-06-01 13:20:10+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 9.7.0-1.el9 started.
my-db-1 | 2026-06-01 13:20:10+00:00 [Note] [Entrypoint]: Initializing database files
my-db-1 | 2026-06-01T13:20:10.948159Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
my-db-1 | 2026-06-01T13:20:10.949117Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 9.7.0) initializing of server in progress as process 81
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.476 * monotonic clock: POSIX clock_gettime
my-db-1 | 2026-06-01T13:20:10.955748Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
my-db-1 | 2026-06-01T13:20:10.966318Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
my-db-1 | 2026-06-01T13:20:12.040123Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
my-db-1 | 2026-06-01T13:20:14.060088Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
my-db-1 | 2026-06-01T13:20:17.379869Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
my-db-1 | 2026-06-01 13:20:17+00:00 [Note] [Entrypoint]: Database files initialized
my-db-1 | 2026-06-01 13:20:17+00:00 [Note] [Entrypoint]: Starting temporary server
my-db-1 | 2026-06-01T13:20:17.431294Z 0 [System] [MY-015015] [Server] MySQL Server - start.
my-db-1 | 2026-06-01T13:20:17.644710Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 9.7.0) starting as process 127
my-db-1 | 2026-06-01T13:20:17.644722Z 0 [System] [MY-015603] [Server] MySQL Server has access to 20 logical CPUs.
my-db-1 | 2026-06-01T13:20:17.644730Z 0 [System] [MY-015603] [Server] MySQL Server has access to 33578594304 bytes of physical memory.
my-db-1 | 2026-06-01T13:20:17.647450Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
my-db-1 | 2026-06-01T13:20:17.666502Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
my-db-1 | 2026-06-01T13:20:18.488989Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
my-db-1 | 2026-06-01T13:20:18.954356Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
my-db-1 | 2026-06-01T13:20:18.954673Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
my-db-1 | 2026-06-01T13:20:18.969275Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.478 * Running mode=standalone, port=6379.
my-db-1 | 2026-06-01T13:20:19.001524Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.479 * <bf> RedisBloom version 8.6.2 (Git=unknown)
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.479 * <bf> Registering configuration options: [
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.479 * <bf> { bf-error-rate : 0.01 }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.479 * <bf> { bf-initial-size : 100 }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.479 * <bf> { bf-expansion-factor : 2 }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.479 * <bf> { cf-bucket-size : 2 }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.479 * <bf> { cf-initial-size : 1024 }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.479 * <bf> { cf-max-iterations : 20 }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.479 * <bf> { cf-expansion-factor : 1 }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.479 * <bf> { cf-max-expansions : 32 }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.479 * <bf> ]
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.480 * Module 'bf' loaded from /usr/local/lib/redis/modules//redisbloom.so
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.495 * <search> Redis version found by RedisSearch : 8.6.3 - oss
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.495 * <search> RediSearch version 8.6.7 (Git=3020486)
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.495 * <search> Low level api version 1 initialized successfully
my-db-1 | 2026-06-01T13:20:19.001640Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '9.7.0' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
my-db-1 | 2026-06-01 13:20:19+00:00 [Note] [Entrypoint]: Temporary server started.
my-db-1 | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
my-db-1 | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
my-db-1 | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
my-db-1 | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
my-db-1 | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
my-db-1 | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
my-db-1 | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.495 * <search> gc: ON, prefix min length: 2, min word length to stem: 4, prefix max expansions: 200, query timeout (ms): 500, timeout policy: return, oom policy: return, cursor read size: 1000, cursor max idle (ms): 300000, max doctable size: 1000000, max number of search results: 1000000, default scorer: BM25STD,
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.496 * <search> Initialized thread pools!
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.496 * <search> Disabled workers threadpool of size 0
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.496 * <search> Subscribe to config changes
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.496 * <search> Subscribe to cluster slot migration events
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.496 * <search> Enabled role change notification
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.496 * <search> Cluster configuration: AUTO partitions, type: 0, coordinator timeout: 0ms
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.497 * Module 'search' loaded from /usr/local/lib/redis/modules//redisearch.so
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.498 * <timeseries> RedisTimeSeries version 80602, git_sha=5d7c61c9f861b5cb83989463595c2c9f6b2bfe63
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.498 * <timeseries> Redis version found by RedisTimeSeries : 8.6.3 - oss
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.498 * <timeseries> Registering configuration options: [
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.498 * <timeseries> { ts-compaction-policy : }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.498 * <timeseries> { ts-num-threads : 3 }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.498 * <timeseries> { ts-retention-policy : 0 }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.498 * <timeseries> { ts-duplicate-policy : block }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.498 * <timeseries> { ts-chunk-size-bytes : 4096 }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.498 * <timeseries> { ts-encoding : compressed }
my-db-1 |
my-db-1 | 2026-06-01 13:20:20+00:00 [Note] [Entrypoint]: Stopping temporary server
my-db-1 | 2026-06-01T13:20:20.514942Z 11 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 9.7.0).
my-db-1 | 2026-06-01T13:20:21.479868Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 9.7.0) MySQL Community Server - GPL.
my-db-1 | 2026-06-01T13:20:21.479896Z 0 [System] [MY-015016] [Server] MySQL Server - end.
my-db-1 | 2026-06-01 13:20:21+00:00 [Note] [Entrypoint]: Temporary server stopped
my-db-1 |
my-db-1 | 2026-06-01 13:20:21+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
my-db-1 |
my-db-1 | 2026-06-01T13:20:21.527549Z 0 [System] [MY-015015] [Server] MySQL Server - start.
my-db-1 | 2026-06-01T13:20:21.720470Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 9.7.0) starting as process 1
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.498 * <timeseries> { ts-ignore-max-time-diff: 0 }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.498 * <timeseries> { ts-ignore-max-val-diff : 0.000000 }
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.498 * <timeseries> ]
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.498 * <timeseries> Detected redis oss
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.499 * <timeseries> Subscribe to ASM events
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.499 * <timeseries> Enabled diskless replication
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.499 * Module 'timeseries' loaded from /usr/local/lib/redis/modules//redistimeseries.so
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.502 * <ReJSON> Created new data type 'ReJSON-RL'
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.503 * <ReJSON> version: 80600 git sha: unknown branch: unknown
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.503 * <ReJSON> Exported RedisJSON_V1 API
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.503 * <ReJSON> Exported RedisJSON_V2 API
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.503 * <ReJSON> Exported RedisJSON_V3 API
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.503 * <ReJSON> Exported RedisJSON_V4 API
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.503 * <ReJSON> Exported RedisJSON_V5 API
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.503 * <ReJSON> Exported RedisJSON_V6 API
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.503 * <ReJSON> Enabled diskless replication
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.503 * <ReJSON> Initialized shared string cache, thread safe: true.
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.503 * Module 'ReJSON' loaded from /usr/local/lib/redis/modules//rejson.so
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.503 * <search> Acquired RedisJSON_V6 API
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.504 * Server initialized
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.504 * Ready to accept connections tcp
my-cache-server-1 | 1:M 01 Jun 2026 13:20:10.504 # WARNING: Redis does not require authentication and is not protected by network restrictions. Redis will accept connections from any IP address on any network interface.
my-db-1 | 2026-06-01T13:20:21.720479Z 0 [System] [MY-015603] [Server] MySQL Server has access to 20 logical CPUs.
my-db-1 | 2026-06-01T13:20:21.720489Z 0 [System] [MY-015603] [Server] MySQL Server has access to 33578594304 bytes of physical memory.
my-db-1 | 2026-06-01T13:20:21.722908Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
my-db-1 | 2026-06-01T13:20:21.752533Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
my-db-1 | 2026-06-01T13:20:22.543737Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
my-db-1 | 2026-06-01T13:20:23.045915Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
my-db-1 | 2026-06-01T13:20:23.046214Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
my-db-1 | 2026-06-01T13:20:23.061577Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
my-db-1 | 2026-06-01T13:20:23.119328Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
my-db-1 | 2026-06-01T13:20:23.119441Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '9.7.0' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
What's next:
Filter, search, and stream logs from all your Compose services
in one place with Docker Desktop's Logs view. docker-desktop://dashboard/logs?appId=compose-practice
5) compose 로 실행된 컨테이너 중지 후 삭제
- Windows PowerShell
PS C:\Users\admin\compose-practice> docker compose down
[+] down 3/3
✔ Container compose-practice-my-cache-server-1 Removed 0.4s
✔ Container compose-practice-my-db-1 Removed 0.9s
✔ Network compose-practice_default Removed 0.3s
PS C:\Users\admin\compose-practice> docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
PS C:\Users\admin\compose-practice> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
비전공자도 이해할 수 있는 Docker 입문/실전| JSCODE 박재성 - 인프런 강의
현재 평점 4.9점 수강생 14,488명인 강의를 만나보세요. 비전공자 입장에서도 쉽게 이해할 수 있고, 실전에서 바로 적용 가능한 Docker 입문/실전 강의를 만들어봤습니다! Docker 기본 개념, Spring Boot를
www.inflearn.com
'강의 실습 > 비전공자도 이해할 수 있는 Docker 입문 실전' 카테고리의 다른 글
| 컨테이너로 실행시킨 Spring Boot가 MySQL에 연결이 안 되는 이유 (1) | 2026.06.03 |
|---|---|
| [실습] Spring Boot, MySQL 컨테이너 동시에 띄워보기 (0) | 2026.06.02 |
| [실습] Docker Compose로 프론트엔드(HTML, CSS, Nginx) 실행시키기 (4) | 2026.05.31 |
| [실습] Docker Compose로 프론트엔드(Next.js) 실행시키기 (0) | 2026.05.30 |
| [실습] Docker Compose로 백엔드(Nest.js) 실행시키기 (0) | 2026.05.29 |
댓글