본문 바로가기
컨테이너/도커

04 도커 이미지 태깅, 등록, 기타

by ^..^v 2019. 5. 18.
728x90
반응형

이미지에 대해 태그를 설정

동일한 이미지명으로 빌드할 경우 이전 태그가 사라짐

root@server:~/docker# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
example/echo        latest              79407db32a2a        About an hour ago   750MB
                            cefd0db84707        About an hour ago   750MB
nginx               latest              53f3fd8007f7        8 days ago          109MB
jenkins             latest              cd14cecfdb3a        10 months ago       696MB
golang              1.9                 ef89ef5c42a9        10 months ago       750MB

docker image tag 명령으로 이미지의 이미지:태그를 새롭게 생성

*** 이미지 ID가 동일한 새로운 이미지:태그가 만들어지는 것을 확인 ***
root@server:~/docker# docker image tag example/echo:latest example/echo:1.0
root@server:~/docker# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
example/echo        1.0                 79407db32a2a        About an hour ago   750MB
example/echo        latest              79407db32a2a        About an hour ago   750MB
                            cefd0db84707        About an hour ago   750MB
nginx               latest              53f3fd8007f7        8 days ago          109MB
jenkins             latest              cd14cecfdb3a        10 months ago       696MB
golang              1.9                 ef89ef5c42a9        10 months ago       750MB

이미지 Docker Hub 등록

docker image tag 명령을 이용해 이미지명을 Docker_Hub_ID/이미지명 형식으로 변경

root@server:~/docker# docker image tag example/echo:latest myanjini/echo:latest
root@server:~/docker# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
example/echo        1.0                 79407db32a2a        About an hour ago   750MB
example/echo        latest              79407db32a2a        About an hour ago   750MB
myanjini/echo       latest              79407db32a2a        About an hour ago   750MB
                            cefd0db84707        About an hour ago   750MB
nginx               latest              53f3fd8007f7        8 days ago          109MB
jenkins             latest              cd14cecfdb3a        10 months ago       696MB
golang              1.9                 ef89ef5c42a9        10 months ago       750MB

docker hub 사이트에 로그인

*** docker login -u docker_hub_username -p docker_hub_password ***
root@server:~/docker# docker login -u myanjini 
Password: 
Login Succeeded

docker image push 이미지명:태그 명령으로 등록

root@server:~/docker# docker image push myanjini/echo:latest
The push refers to a repository [docker.io/myanjini/echo]
957c7aed362a: Pushed 
1a699735e10e: Pushed 
186d94bd2c62: Mounted from library/golang 
24a9d20e5bee: Mounted from library/golang 
e7dc337030ba: Mounted from library/golang 
920961b94eb3: Mounted from library/golang 
fa0c3f992cbd: Mounted from library/jenkins 
ce6466f43b11: Mounted from library/jenkins 
719d45669b35: Mounted from library/jenkins 
3b10514a95be: Mounted from library/jenkins 
latest: digest: sha256:4c819809883ec60076cb4476d6c84b22e711cb2f1c76cecd5c6c0a7485194d13 size: 2417

Docker Hub에서 등록 확인 및 검색

동일한 이름의 컨테이너를 삭제 후 컨테이너 실행

root@server:~/docker# docker container run --name hello -it -d -p 8889:8080 example/echo:latest /bin/bash ⇐ hello 이름으로 컨테이너 실행
1c920503b9eb5f591d70ae9116151943658001955793611a5762b388c5dbaa64
root@server:~/docker# docker container ls
CONTAINER ID        IMAGE                 COMMAND             CREATED             STATUS              PORTS                    NAMES
1c920503b9eb        example/echo:latest   "/bin/bash"         3 seconds ago       Up 3 seconds        0.0.0.0:8889->8080/tcp   hello

root@server:~/docker# docker container run --name hello -it -d -p 8888:8080 example/echo:latest /bin/bash ⇐ 동일한 이름(hello)으로 컨테이너 실행
docker: Error response from daemon: Conflict. The container name "/hello" is already in use by container "1c920503b9eb5f591d70ae9116151943658001955793611a5762b388c5dbaa64". You have to remove (or rename) that container to be able to reuse that name. ⇐ 이름 중복 오류 발생
See 'docker run --help'.

root@server:~/docker# docker container stop hello ⇐ (A) 기존에 실행 중이던 hello 컨테이너 중지 
hello
root@server:~/docker# docker container run --name hello -it -d -p 8888:8080 example/echo:latest /bin/bash ⇐ hello 이름으로 컨테이너 실행
docker: Error response from daemon: Conflict. The container name "/hello" is already in use by container "1c920503b9eb5f591d70ae9116151943658001955793611a5762b388c5dbaa64". You have to remove (or rename) that container to be able to reuse that name. ⇐ 이름 중복 오류 발생 (중지 상태의 컨테이너는 상태를 저장하고 있으며, 언제든지 재실행이 가능) → 동일한 이름으로 컨테이너 실행하기 위해서는 반드시 삭제해 줘야 함
See 'docker run --help'.
root@server:~/docker# docker container rm hello ⇐ (B) 컨테이너 삭제
hello
root@server:~/docker# docker container run --name hello -it -d -p 8888:8080 example/echo:latest /bin/bash ⇐ hello 이름으로 컨테이너 실행
c79b5b943bfbe57d86c7bdbfdddbcf3e2c15c15c476d5a0d05875e446116f253 ⇐ 컨테이너 실행 확인

root@server:~/docker# docker container rm -f hello ; docker container run --name hello -it -d -p 8888:8080 example/echo:latest /bin/bash ⇐ (A), (B) 과정을 한번에 수행 컨테이너를 강제로 삭제 후 컨테이너 실행
hello
4ab9be3bdaa20326935618316073ce5a402eeccd809d52175cf276af35ff9812 
728x90
반응형

댓글