Skip to Content
Suffering builds character
아카이브25.devopsDocker특징2.이미지 관리2.환경변수를 통해 컨테이너의 동작 변경

2.환경변수를 통해 컨테이너의 동작 변경

도커는 컨테이너를 실행할 때 별도의 환경 변수를 통해 컨테이너의 동작을 변경할 수 있음

1-1. blog.sixeyed.com가 아닌 다른 서비스로 요청 테스트하도록 동작 변경

docker stop 명령어를 통해 실행 중인 컨테이너 중지

terminal
docker stop web-ping

→ web-ping 이름으로 실행된 컨테이너 일시중지

전체 컨테이너 상태 조회

terminal
docker ps -a
terminal
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8faf1bd2218c diamol/ch03-web-ping "docker-entrypoint.s…" 5 minutes ago Exited (137) 5 seconds ago web-ping

→ STATUS가 Exited로 컨테이너가 중지되었음

해당 컨테이너 제거

terminal
docker rm web-ping

별도의 환경 변수 옵션을 통해 컨테이너 내 프로그램이 다른 서비스로 요청하여 동작할 수 있도록 변경

docker run --env TARGET=google.com diamol/ch03-web-ping

--env TARGET=google.com 환경 변수 옵션인 --env 을 통해 TARGET 변수에 google.com값을 지정

실행 결과

terminal
** web-ping ** Pinging: google.com; method: HEAD; 3000ms intervals Making request number: 1; at 1709462150716 Got response status: 301 at 1709462150947; duration: 231ms Making request number: 2; at 1709462153719 Got response status: 301 at 1709462153877; duration: 158ms Making request number: 3; at 1709462156722

→ 컨테이너 실행 시 --detach를 적용하지 않았기 때문에 포그라운드에서 동작하게 되어 실행 결과가 프롬프트에 바로 출력됨

1-2. 다운받은 이미지, 컨테이너 제거

terminal
docker system prune -a
Last updated on