docker compose 사용해 보자.
이번에 토이프로젝트를 하면서, 배포는 docker-compose로 하기로 했다. 그래서 조사해보았다. 본 작성글은 조원들과 공유하기 위해 만들 글입니다. HanDDAM 화이팅!!! ㅎㅎ
설치 방법
docker compose options 사용
-f
하나의 이상의 파일의 이름과 경로를 지정하는데 사용합니다.
- 단일 작성 파일 경로 지정 예시
docker-compose -f docker-compose-test.yml up
- 여러 compose 파일 지정 가능함
docker compose command 사용
up
컨테이너를 생성하고 시작하는데 사용합니다.
down
모든 서비스 컨테이너를 한 번에 정지 시키고 삭제할 때 사용합니다.
ps
서비스 컨테이너를 확인할 수 있습니다.
- 서비스 컨테이너 확인
docker-compose ps
- 서비스 컨테이너 네임 확인
docker-compose ps --service
start
서비스 컨테이너를 실행시킬 때 사용합니다.
docker-compose start {서비스 컨테이너 이름}
stop
서비스 컨테이너를 정지시킬 때 사용합니다.
docker-compose stop {서비스 컨테이너 이름}
rm
서비스 컨테이너를 삭제 할 때 사용합니다.
docker-compose rm
- 서비스 컨테이너를 묻지도 따지지도 않고 삭제
docker-compose rm -f {서비스 컨테이너 이름}
- 서비스 컨테이너를 삭제하기 전에 본 컨테이너가 실행중이라면 중지하고 삭제
- 서비스 컨테이너를 묻지도 따지지도 않고 삭제
docker-compose rm -s {서비스 컨테이너 이름}
logs
서비스 컨테이너의 로그를 보고 싶을 때 사용합니다.
- 서비스 컨테이너의 로그 확인
docker-compose logs {서비스 컨테이너 이름}
- 서비스 컨테이너의 로그 확인 실시간
docker-compose logs -f {서비스 컨테이너 이름}
exec
실행 중인 서비스 컨테이너 안에 들어가고 싶을 때 사용합니다.
docker-compose exec -f {서비스 컨테이너 이름}
본 내용을 정리하면서 알게된 내용
알게 된 이슈
헉..! 실행중인 서비스 컨테이너를 확인 할 수 없었다.
구글링을 한 결과, 참고사이트
- .yml이나 .yaml 확장자 있는지 확인해보세요!!
-> (나의 대답) 당근 있지요...그런데..왜 안 될까.. ㅜㅜㅜ
- 권한 문제인 것 같아요.
-> 권한을 완전 다 열었어요. 그런데 안된다..
- snap으로 말고, apt-get 사용해서 설치보세요.
-> apt-get 활동해서 설치 했습니다. ㅠㅠㅠ
- 위에서 지원해주는 파일 이름 중, 하나의 파일을 본 디렉토리에 생성해 보았다. (해결)
docker-compose.yml, docker-compose.yaml, compose.yml, compose.yaml 없다고, 투정?을 부려서 그냥 하나 만들어 줬다. 헉! 근데 된다. 대박!
혹시 위의 3개의 방법으로도 해결하지 못하셨다면, 4번 방법을 한번 시도해보세요. (찜찜.. 원인은 모르지만, 되었다..)
알게 된 내용
docker-compose에 대해 지금 공부중이라서 모르는 것일 수도 있지만, 명령 대상이 서비스 컨테이너 이름
으로 한정되어 있는 것 같았다. docker는 컨테이너 이름 또는 컨테이너 아이디로 가능한데..
서비스 컨테이너 이름을 꼭 확인해봐야 해서 불편했다.
그 외
Options:
-f, --file FILE Specify an alternate compose file
(default: docker-compose.yml)
-p, --project-name NAME Specify an alternate project name
(default: directory name)
--profile NAME Specify a profile to enable
-c, --context NAME Specify a context name
--verbose Show more output
--log-level LEVEL Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
--ansi (never|always|auto) Control when to print ANSI control characters
--no-ansi Do not print ANSI control characters (DEPRECATED)
-v, --version Print version and exit
-H, --host HOST Daemon socket to connect to
--tls Use TLS; implied by --tlsverify
--tlscacert CA_PATH Trust certs signed only by this CA
--tlscert CLIENT_CERT_PATH Path to TLS certificate file
--tlskey TLS_KEY_PATH Path to TLS key file
--tlsverify Use TLS and verify the remote
--skip-hostname-check Don't check the daemon's hostname against the
name specified in the client certificate
--project-directory PATH Specify an alternate working directory
(default: the path of the Compose file)
--compatibility If set, Compose will attempt to convert keys
in v3 files to their non-Swarm equivalent (DEPRECATED)
--env-file PATH Specify an alternate environment file
Commands:
build Build or rebuild services
config Validate and view the Compose file
create Create services
down Stop and remove resources
events Receive real time events from containers
exec Execute a command in a running container
help Get help on a command
images List images
kill Kill containers
logs View output from containers
pause Pause services
port Print the public port for a port binding
ps List containers
pull Pull service images
push Push service images
restart Restart services
rm Remove stopped containers
run Run a one-off command
scale Set number of containers for a service
start Start services
stop Stop services
top Display the running processes
unpause Unpause services
up Create and start containers
version Show version information and quit
마무리
왜 docker-compose 를 쓰는지 모르겠다. docker에도 service 개념이 있는데..굳이 써야하는가? 라는 생각이 든다.
좀 더 공부해봐야겠다.
Author And Source
이 문제에 관하여(docker compose 사용해 보자.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@locodingve/docker-compose-사용해-보자저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)