도커허브를 사용해 배포환경으로 이전-1 : Docker push

horiz.d·2023년 5월 19일
0

PJ: Aight

목록 보기
10/17
post-thumbnail

Official Ref: https://docs.docker.com/docker-hub/repos/


도커 레포지터리 생성

프라이빗 설정으로 생성했음.


어떤 이미지를 업로드 해야할까?

아래의 내 docker 로그를 보자.
현재 구동중인 containers는 장고/nginx/postgres로 세개의 컨테이너가 있다.

이들은 각각 모태인 이미지를 가지고 있음을 확인 가능.

하지만 내 docker-compose를 보자.
아래를 보면 web,db,nginx 중 build 설정이 존재하는 것은 web에 해당하는 django 하나 뿐이다.

실제로 Dockerfile을 만들어 관리하는것은 django 뿐으로, 이외 db,nginx의 경우 각각 postgres:13nginx:1.19.0-alpine 오픈소스로 빌드된 이미지를 가져온다는 사실을 알 수 있다.

따라서 레포를 만들어 push하고, 배포환경에 pull해야 할 이미지는 only django (web) 뿐이라고 생각할 수 있다.

version: "3.8"

services:
  web:
    restart: always
    image: django
    depends_on:
      - db
    build:
      context: ./cmd8_server
      dockerfile: Dockerfile

    command:
      ["gunicorn", "cmd8_server.wsgi:application", "--bind", "0.0.0.0:8000"]
    volumes:
      - ./cmd8_server:/cmd8_server
    expose:
      - 8000
    env_file:
      - ./cmd8_server/.env
  nginx:
    restart: always
    image: nginx:1.19.0-alpine
    volumes:
      - ./nginx:/etc/nginx/conf.d
      - static_volume:/home/app/web/static
      - media_volume:/home/app/web/media
    ports:
      - "80:80"
  db:
    image: postgres:13
    restart: always
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    environment:
      POSTGRES_USER: xxx
      POSTGRES_PASSWORD: xxx
      POSTGRES_DB: xxx
      DJANGO_SETTINGS_MODULE: cmd8_server.settings

volumes:
  postgres_data:
  static_volume:
  media_volume:

하지만 만일 db, nginx의 기본 설정 및 버전을 바꿔야 할 경우 이미지를 직접 빌드해야 할 수 있고, 이러한 경우 도커 레포에 이들을 업로드하여 비슷하게 관리해줄 수 있겠다.


도커 Repository에 이미지 push

  1. docker images로 이미지 목록 확인
  1. dokcer 이미지에 태그 붙이기
    docker tag ${Image ID} ${docker user name}/#{docker repo name}:${Tag Name - 임의 설정}

  2. docker 이미지 레포에 Push
    `docker push 도커유저이름/{도커 유저 이름}/{도커 레포 이름}:${태그명}

  3. 확인

profile
가용한 시간은 한정적이고, 배울건 넘쳐난다.

0개의 댓글