본문 바로가기
OpenSource/Docker

[Docker] docker exec [container] bash -c [command]

by SooooooooS 2024. 7. 16.
728x90

docker exec [컨테이너이름] /bin/bash -c "실행할 스크립트 명령어" 

 

코드를 분석하다가 위의 명령어를 실행하는 코드를 봤다.

대충은 어떤 동작을 하는지 알지만 정확하게 몰라서 이번 기회에 정리해본다.

1️⃣ docker exec

Execute a command in a running container
실행 중인 컨테이너에서 명령어를 실행한다.
  • -i , --interactive: STDIN(표준입출력) 유지
  • -t, --tty : 의사 터미널 할당
  • -it : 컨테이너 내에서 셀과 같은 대화형 인터페이스를 제공받을 수 있다.
docker exec -it [container_id] /bin/bash

실행된 도커 컨테이너에 /bin/bash 쉘을 사용하기 위해 이 명령어를 사용했다.

2️⃣ 쉘 옵션

-c 옵션 : 뒤에 오는 문자열을 명령어로 인식하도록 하는 것을 의미

[참고]

✏️ 공식문서

https://docs.docker.com/reference/cli/docker/container/exec/

 

docker exec

 

docs.docker.com

✏️ 참고 블로그

https://www.lainyzine.com/ko/article/docker-exec-executing-command-to-running-container/

 

docker exec 사용법: 실행중인 컨테이너에 명령어 실행하는 방법

docker exec는 이미 실행된 컨테이너 환경에 새로운 프로세스를 추가로 실행해, 컨테이너 환경을 디버깅할 수 있게 도와주는 명령어입니다.

www.lainyzine.com

✏️ Python 공식문서(cmd)

https://docs.python.org/ko/3/using/cmdline.html

 

1. Command line and environment

The CPython interpreter scans the command line and the environment for various settings. CPython implementation detail: Other implementations’ command line schemes may differ. See Alternate Impleme...

docs.python.org

 

 

728x90

'OpenSource > Docker' 카테고리의 다른 글

[Docker] Docker-Compose로 MySQL 띄우기  (0) 2024.02.13
[Docker] mySQL 띄우기 (Mac)  (0) 2024.01.29