본 게시물은 스스로의 공부를 위한 글입니다.
틀린 내용이 있을 수 있습니다.
docker commit
을 사용한다.docker ps
로 도커 Name 확인docker commit [도커NAME] [내가 만든 이미지 이름 지정]
docker imags
로 새로운 이미지 확인 가능$ docker run -it --name git ubuntu:latest bash //우분투 실행
root@2f8bfff679f9:/ git
bash: git: command not found //현재 git이 설치되어 있지 않다
root@2f8bfff679f9:/ apt-get update
root@2f8bfff679f9:/ apt-get install -y git //git 설치
root@2f8bfff679f9:/ git --version
git version 2.17.1 //git이 설치되었다.
$ docker images | grep ubuntu
ubuntu latest cf0f3ca922e0 5 days ago 64.2MB //내가 처음에 설치한 오리지널 우분투 이미지만 존재
$ docker commit git ubuntu:git //git이란 이름의 컨테이너를 ubuntu:git이름의 이미지 파일로 생성
$docker images | grep ubuntu //새로 만들어진것을 확인할 수 있다.
ubuntu:git f95008381e22 17 seconds ago 186MB
ubuntu latest cf0f3ca922e0 5 days ago 64.2MB
위에서 살펴본 도커 commit 처럼 build도 새로운 도커 이미지를 생성하는데 사용한다.
commit vs build
실행중인 container에서 image를 만들땐 commit
Dockerfile을 통해서 image를 만들 땐 build
결과적으론 image를 만드는 건 똑같지만, commit은 백업느낌, build는 생성하는 느낌이다.
docker build -t [이름공간]/[이미지이름]:[태그] .
-f <Dockerfile 위치>
옵션을 사용해 다른 위치의 Dockerfile 파일 사용 가능 -t
명령어로 도커 이미지 이름을 지정가능 FROM [--platform=<platform>] <image>[:<tag>] [AS <name>]
베이스 이미지 지정
FROM ubuntu:latest
FROM node:12
FROM python:3
COPY <src> <dest>
이미지에 파일 복사
COPY index.html /var/www/html/
COPY ./app /usr/src/app
RUN <command>
명령어 실행.
RUN apt-get update
RUN npm install
WORKDIR /path/to/workdir
작업 디렉토리 변경
WORKDIR /app
EXPOSE <포트번호>
컨테이너에서 사용하는 포트 정보
EXPOSE 8000
CMD ["executable","param1","param2"]
, CMD command param1 param2
컨테이너 매번 실행시 수행할 명령어. 하나의 CMD만 작성 가능하며, 중복일 경우 맨 마지막만 유효하다.
CMD ["node", "app.js"]
CMD node app.js
FROM ubuntu:20.04
RUN apt update && apt install -y python3
WORKDIR /var/www/html //경로가 있다면 이동, 없다면 생성
CMD ["python3", "-u", "-m", "http.server"]
docker login
docker push {ID}/example
docker pull {ID}/example