build-tag-publish-image

Build, tag and publish an image

doc

  • 정의
    • Building images: Dockerfile를 기반으로 image를 생성하는 process
    • Tagging images: image에 이름을 붙이고, image를 배포 위치를 결정
    • Publishing images: image를 container registry를 통해서 패포하는 process

Building images

# `.`는 Dockerfile의 위치를 뜻함 
docker build .
# 결과에 `sha256:9924dfd9350407b3df01d1a0e1033b1e543523ce7d5d5e2c83a724480ebe8f00`와 같은 문자열이 나온다.

# 아래 명령어를 통해서 실행할 수 있다.
docker run sha256:9924dfd9350407b3df01d1a0e1033b1e543523ce7d5d5e2c83a724480ebe8f00

Tagging images

image에 이름을 붙이는 행위, 전체 이름은 아래 구조를 가진다.

[HOST[:PORT_NUMBER]/]PATH[:TAG]
  • HOST: registry hostname (docker hub가 기본 값) ex) ghcr.io
  • PORT_NUMBER: registry port number
  • PATH: image의 path이다.
  • TAG: image의 버전 혹은 varient id (lastest가 기본 값)
# 아래와 같이 tag를 달 수 있다. (-t or --tag)
docker build -t my-username/my-image .

# 아래와 같이 image에 tag를 추가할 수 있다.
docker image tag my-username/my-image another-username/another-image:v1

Publishing images

# 아래와 같이 registry에 image를 올릴 수 있다.
docker push my-username/my-image