본문 바로가기
Docker/docs

[Docker] [docs] 03. 애플리케이션 업데이트, 컨테이너 빌드

by NJ94 2023. 12. 4.

https://docs.docker.com/get-started/03_updating_app/

 

Update the application

Making changes to your application

docs.docker.com

 

Docker 소스 코드 업데이트

1. 파일에서 코드 수정.


  
- <p className="text-center">No items yet! Add one above!</p>
+ <p className="text-center">You have no todo items yet! Add one above!</p>

 

2. 명령어를 사용하여 업데이트전 버전의 이미지 빌드 docker build


  
$ docker build -t getting-started .

 

3. 업데이트 된 코드를 사용하여 새 컨테이너 시작


  
$ docker run -dp 127.0.0.1:3000:3000 getting-started

 

 

에러 발생 시,


  
docker: Error response from daemon: driver failed programming external connectivity on endpoint laughing_burnell
(bb242b2ca4d67eba76e79474fb36bb5125708ebdabd7f45c8eaf16caaabde9dd): Bind for 127.0.0.1:3000 failed: port is already allocated.

 

이전 컨테이너가 계속 실행되는 동안 새 컨테이너를 시작할 수 없기 때문에 오류가 발생했습니다. 그 이유는 이전 컨테이너가 이미 호스트의 포트 3000을 사용하고 있고 머신(컨테이너 포함)의 하나의 프로세스만 특정 포트를 수신할 수 있기 때문입니다. 이 문제를 해결하려면 기존 컨테이너를 제거해야 합니다.

 

컨테이너 제거

 

1. 컨테이너 id 가져오기


  
$ docker ps

 

2. 위의 명령어 입력 시, 출력되는 로그에서 컨테이너 id 복사.


  
$ docker stop <the-container-id>

 

3. 컨테이너 중지 시, 아래의 명령어로 제거.


  
$ docker rm <the-container-id>

 

force 명령 에 플래그를 추가하면 단일 명령으로 컨테이너를 중지하고 제거할 수 있습니다 
docker rm -f <the-container-id>