Image: 실행할 파일들의 집합
Container: 파일들의 실행 프로세스
docker1: ec2-52-78-217-175.ap-northeast-2.compute.amazonaws.com
docker2: ec2-3-34-166-247.ap-northeast-2.compute.amazonaws.com
docker3: ec2-52-79-159-103.ap-northeast-2.compute.amazonaws.com
기본 설정
linux(ubuntu)에 docker 설치
curl -fsSl <https://download.docker.com/linux/ubuntu/gpg> | apt-key add -
add-apt-repository "deb [arch=amd64] <https://download.docker.com/linux/ubuntu> $(lsb_release -cs) stable"
apt-get update
apt-get install -y docker-ce
docker --version
Docker version 19.03.12, build 48a66213fe
만약 두 번째 줄 에서 오타가 날 경우
vim /etc/apt/sources.list
# 오류를 일으킨 패키지 항목을 지운다.
도커 허브에서 계정 생성
도커 데스크탑 설치
# 설치가 끝나고 도커 버전확인
$ docker --version
도커 이미지 생성
# docker 파일 생성 - 일반적으로 Dockerfile로 생성하는듯
$ touch Dockerfile
# 스크립트 작성
$ vim Dockerfile
####################################################################
# From을 이용해 다른사람이 올려놓은 python3.7 이미지를 사용한다.
FROM python:3.7
####################################################################
RUN apt-get update && apt-get install -y --no-install-recommends \\
nginx vim net-tools openssh-server
RUN apt-get install -y --no-install-recommends \\
python3-setuptools \\
python3-pip \\
python3-dev \\
python3-venv \\
git \\
&& \\
apt-get clean && \\
rm -rf /var/lib/apt/lists/*
CMD python -c "print('hello world')"
####################################################################
FROM: 누군가 올려놓은 기존 이미지를 사용
RUN: 쉘 커맨드에서 사용할 명령
CMD: 도커 설정이 완료되고 실행될 명령(파이썬을 실행한 후 print('hello world') 명령 → 화면에 hello world가 출력된다.)
# Docker_default
FROM ubuntu:18.04
# port number
EXPOSE 8080
# install util
RUN apt-get update && apt-get install -y --no-install-recommends \\
nginx vim net-tools openssh-server
# install python
RUN apt-get install -y --no-install-recommends \\
python3.7\\
python3-setuptools \\
python3-pip \\
python3-dev \\
python3-venv \\
git \\
&& \\
apt-get clean && \\
rm -rf /var/lib/apt/lists/*
# 한글 설정
RUN apt-get install locales
RUN apt-get install -y \\
language-pack-ko && \\
dpkg-reconfigure locales && \\
locale-gen ko_KR.UTF-8 && \\
/usr/sbin/update-locale LANG=ko_KR.UTF-8
# 한글을 출력하기 위해 환경변수 등록
ENV LANG=ko_KR.UTF-8
ENV LANGUAGE=ko_KR.UTF-8
ENV LC_ALL=ko_KR.UTF-8
# 파이썬에서 한글을 사용할 수 있도록 환경변수 등록
ENV PYTHONIOENCODING=UTF-8
# 빌드 이미지
$ docker build -t <your-tag> -f Dockerfile .
# ex) docker build -t hello-world -f Dockerfile .
-t: 태그