1. 이미지 관련 명령어
(1) tag
- 단순히 새로운 이름만 붙여주는 것. 이미지 자체는 똑같기 때문에 IMAGE ID는 같다
docker tag centos:centos7 91root/docker:centos7
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
91root/docker centos7 eeb6ee3f44bd 21 months ago 204MB
centos centos7 eeb6ee3f44bd 21 months ago 204MB
...
(2) push
- 생성된 이미지를 개인 리포지토리에 업로드 하는 명령어
docker push 91root/docker:centos7
(3) commit
- 이미지를 생성하지만, 기존의 이미지와 다른 부분만 레이어로 추가해서 생성하는 방식
- 태그를 다르게 입력해야함.
docker cp /etc/services os7:/tmp
docker commit os7 91root/docker:commit
docker inspect 91root/docker:centos7
...
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:174f5685490326fc0a1c0f5570b8663732189b327007e47ff13d2ca59673db02"
...
docker inspect 91root/docker:commit
...
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:174f5685490326fc0a1c0f5570b8663732189b327007e47ff13d2ca59673db02",
"sha256:b3a5d56724c95fc3ef091ba5df15256e5a25d0b38afbf669354caa00b39c6dc6"
...
(4) export / import
- export : 컨테이너의 파일시스템을 추출하여 아카이브 파일로 생성하는 명령어
- import : 아카이브 파일을 이미지로 불러오는 명령어
- import로 만든 이미지는 같은 구성이더라도 레이어가 새롭게 생성, config값도 초기화됨
docker export -o export.tar os7
tar -tf export.tar
docker import export.tar 91root/docker:import
2. Dockerfile
- Dockerfile을 통해서 기존 이미지로부터 원하는 대로 customizing한 이미지를 생성할 수 있다.
FROM centos:7
MAINTAINER 91root
RUN yum -y install httpd
CMD ["/usr/sbin/httpd","-D","FOREGROUND"]
ENV WEBPORT 80
EXPOSE ${WEBPORT}
EXPOSE 443
VOLUME /var/www/html
COPY index.html /var/www/html/index.html
docker build -t 91root/docker:centosweb .
docker run -d --name centosweb -v centvol:/var/www/html 91root/docker:centosweb
3. 프라이빗 저장소
- 이미지 저장을 할 때, 도커허브가 아닌 프라이빗 저장소를 활용할 수도 있다.
(1) Docker registry
- 아주 간단한 프라이빗 저장소
- 5000포트를 사용
docker pull registry:2
docker run -d -p 5000:5000 --name registry registry:2
docker image tag centos:latest localhost:5000/mycentos:v1
docker push localhost:5000/mycentos:v1
curl -X GET http://localhost:5000/v2/_catalog
curl -X GET http://localhost:5000/v2/mycentos/tags/list
docker pull localhost:5000/mycentos:v1
docker run -itd --name os localhost:5000/mycentos:v1
(2) Harbor
- 보안 및 관리 등 부가적인 기능이 포함된 프라이빗 저장소
curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
curl -LO https://github.com/goharbor/harbor/releases/download/v2.0.2/harbor-offline-installer-v2.0.2.tgz
cp harbor.yml.tmpl harbor.yml
vim harbor.yml
5 hostname: harbor.nobreak.co.kr
12
13
14
15
16
17
18
vim /etc/docker/daemon.json
{
"insecure-registries" : ["192.168.56.190"]
}
systemctl restart docker
./install.sh
vim /etc/hosts
docker login -u admin -p Harbor12345 192.168.56.190
docker tag centos:latest 192.168.56.190/library/docker:centos
docker push 192.168.56.190/library/docker:centos
docker rmi 192.168.56.190/library/docker:centos
docker pull 192.168.56.190/library/docker:centos
(참고) HTTPS 로 구축하기
openssl genrsa -out ca.key 4096
openssl req -x509 -new -nodes -sha512 -days 3650 -key ca.key -out ca.crt
openssl genrsa -out harbor.nobreak.or.kr.key 4096
openssl req -sha512 -new -key harbor.nobreak.or.kr.key -out harbor.nobreak.or.kr.csr
openssl x509 -req -sha512 -days 3650 -extfile v3.ext -CA ca.crt -CAkey ca.key -CAcreateserial -in harbor.nobreak.or.kr.csr -out harbor.nobreak.or.kr.crt
openssl x509 -inform PEM -in harbor.nobreak.or.kr.crt -out harbor.nobreak.or.kr.cert
mkdir -p /etc/docker/certs.d/harbor.nobreak.co.kr/
cp harbor.nobreak.or.kr.cert /etc/docker/certs.d/harbor.nobreak.co.kr/
cp harbor.nobreak.or.kr.key /etc/docker/certs.d/harbor.nobreak.co.kr/
cp ca.crt /etc/docker/certs.d/harbor.nobreak.co.kr/
systemctl restart docker
https:
port: 443
certificate: /etc/docker/certs.d/harbor.nobreak.co.kr/harbor.nobreak.or.kr.cert
private_key: /etc/docker/certs.d/harbor.nobreak.co.kr/harbor.nobreak.or.kr.key
cp harbor.nobreak.or.kr.crt /etc/pki/ca-trust/source/anchors/
cp ca.crt /etc/pki/ca-trust/source/anchors/
update-ca-trust
./prepare
docker-compose down -v
docker-compose up -d
docker login harbor.nobreak.co.kr
docker tag centos:latest harbor.nobreak.co.kr/library/docker:v1
docker push harbor.nobreak.co.kr/library/docker:v1