내일배움캠프 - 도커 실무 강의 1주차 개발일지

Dongwoo Kim·2022년 7월 12일
0

스파르타 코딩클럽

내일배움캠프 AI 웹개발자양성과정 2회차

도커 실무 강의 1주차 개발일지

1. Docker

: 개발 및 배포, 서비스 운영에 있어서 실행환경, 코드, 라이브러리, 설정 파일 등을 쉽게 관리하기위한 도구

Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers.
-Docker (software) from Wikipedia

docker의 구성요소 (출처: https://docs.docker.com/get-started/overview/)

1) Docker container

: 애플리케이션의 개발, 실행, 배포 등을 위해 표준화된 단위의 패키지

Package Software into Standardized Units for Development, Shipment and Deployment

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.

- www.doker.com/resources/what-container/

2) Docker image

: 컨테이너를 빌드하는 데 사용되는 읽기 전용 템플릿, 애플리케이션을 저장하고 배송(ship)하는데 사용됨

A Docker image is a read-only template used to build containers. Images are used to store and ship applications.
- Docker (software) from Wikipedia

3) Docker registry

: Docker image들을 업로드(push)하고 다운로드(pull)받기위한 공간

A Docker registry is a repository for Docker images. Docker clients connect to registries to download ("pull") images for use or upload ("push") images that they have built.
- Docker (software) from Wikipedia

2. Docker 간단한 명령어

1) docker run

: container 생성

docker run [options] {image_name} [command]

options

  • -d : docker container가 백그라운드에서 실행됨
  • -p host_port:container_port : container의 포트와 host의 포트를 연결
docker run -d -p 80:5000 docker-memo:version1

2) docker ps, docker ps -a

  • docker ps : 현재 실행중인 container 상태 확인
  • docker ps -a : 모든 container 상태확인 (stop된 container도 포함)

3) docker stop

: container 정지

docker stop {container_id|conatinaer_name}
docker stop docker-memo:version1

4) docker restart

: container 재시작

docker restart {container_id|container_name}
docker restart docker-memo:version1

5) docker rm

: container 삭제

docker rm {container_id}
docker rm 66adafa8f672

3. Docker image

1) Dockerfile

: Docker image를 생성하기위한 파일

FROM python:3.8

ADD requirements.txt .

RUN pip install -r requirements.txt

ADD templates templates

ADD app.py .

CMD ["python", "app.py"]
  • FROM : Docker image를 생성할 때 기본적으로 사용할 base image
  • ADD src dst : host의 src 위치에 있는 파일이나 폴더를 dst 위치에 저장
  • RUN script : script를 실행
  • CMD : Docker image를 실행할 때 자동으로 실행되는 명령어

2) docker build

docker build [OPTIONS] PATH

options

  • -t : Docker image에 {image_name}:{tag}의 형태로 name 과 tag 설정 가능, {tag}를 붙이지 않을 경우 자동으로 latest로 설정됨
docker build -t docker-memo:version1 .

3) docker images

: Docker image 목록 확인 가능

4) docker rmi

: Docker image 삭제

docker rmi ({image_name}:{tag} | {Iamge ID})
docker rmi docker-memo:version1

4. Docker Hub

: Docker registry를 관리할 수 있는 서비스

Docker Hub is a service provided by Docker for finding and sharing container images with your team. It is the world’s largest repository of container images with an array of content sources including container community developers, open source projects and independent software vendors (ISV) building and distributing their code in containers.
- https://docs.docker.com/docker-hub/

1) 업로드하기 (push)

1-1) Docker image build

: docker hub의 가입한 아이디(user_id)를 포함

docker build -t {user_id}/docker-memo:version2 .
docker build -t kimphysicsman/docker-memo:version2 .

1-2) docker hub에 로그인

docker login

1-3) registry에 push

docker push {user_id}/docker-memo:version2
docker push kimphysicsman/docker-memo:version2

5. 코드

https://github.com/kimphysicsman/docker-memo

profile
kimphysicsman

0개의 댓글