kevin@hostos1:~$ docker run \
> --volume=/:/rootfs:ro \
> --volume=/var/run:/var/run:rw \
> --volume=/sys:/sys:ro \
> --volume=/var/lib/docker/:/var/lib/docker:ro \
> --publish=9559:8080 \
> --detach=true \
> --name=cadvisor \
> --restart=always \
> google/cadvisor:latest
0) 개발팀 요청 ▶ 분석 ▶ OS, Package, ENV, ... ▶ 작업 계획서 작성
1) Dockerfile 작성 ▶ Build
이미지 만드는 과정
Build 성공과 실패 확인(성공해도 이미지가 잘못 생성될 가능성 有)
2) docker run 컨테이너 테스트
3) 개발팀에 공유
- Registry(public/private)에 push
- github(source 공유): CI/CD 가능 (지속적 통합/지속적 배포)
- 내용이 수정되면 자동으로 새로 만듦
4) 개발팀 활용: 2번 서버에서 테스트
명령어 | 설명 | 명령어 | 설명 |
---|---|---|---|
FROM | 베이스 image 저장 (image:tag, OS) | ADD | 파일 및 디렉터리 추가(복사) (URL, 압축파일(tar, tar.gz 자동 해제 기능) |
MAINTAINER | Dockerfile 작성자 저장 | COPY | 파일 복사(host ▶ 이미지에 저장) |
RUN | linux 명령어 실행(설치) (image build 시 동작) | VOLUME | 볼륨 마운트(directory) (host와 공유할 디렉터리) |
CMD | 데몬 실행(container 실행 시 동작) | ENTRYPOINT | 데몬 실행, 변수 실행, arg 실행(container 실행 시 동작할 변수 |
LABEL | 라벨 설정(설명, key=value) | USER | 사용자 설정 (useradd와 동일) |
EXPOSE | 노출(open)될 포트 export Ex) 80/tcp | WORKDIR | 작업 디렉터리 지정 (container에 bash로 접근 시 시작 경로, image 내에서 cd 역할) |
ENV | 내부 환경변수 설정 | ONBUILD | build 완료 후 실행될 명령어 (두 번째 build 시 수행될 명령) |
예: "my-python:1.0" image 개발
FROM ubuntu:18.04
-y
옵션 필요RUN apt -y update
RUN apt -y install python:3.8-alpine3.14
kevin@hostos1:~$ cd LABs
kevin@hostos1:~/LABs$ mkdir appimages && cd $_
kevin@hostos1:~/LABs/appimages$ vi index.html
<html>
<head>
<title>Docker Container App</title>
<style>body {margin-top: 40px; background-color: #87CEEB; background-image: url("docker_logo.png");}
</style>
</head>
<body>
<div style=color:black;text-align:center>
<h1> Docker Container Sample Application. </h1>
<h2> Welcome to Container world! </h2>
<p>Your application is now running on a container in Docker Container.</p>
</div>
</body>
</html>
kevin@hostos1:~/LABs/appimages$ vi Dockerfile_nginx
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y -q nginx
COPY index.html /var/www/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
webapp:1.0
kevin@hostos1:~/LABs/appimages$ docker build -f Dockerfile_nginx -t webapp:1.0 .
Sending build context to Docker daemon 3.072kB
Step 1/5 : FROM ubuntu:18.04
---> 35b3f4f76a24
Step 2/5 : RUN apt-get update && apt-get install -y -q nginx
---> Running in e87f1b4c5e86
... (update)
Removing intermediate container e87f1b4c5e86
---> f7e36acd4e1f
Step 3/5 : COPY index.html /var/www/html
---> 3e210b13a333
Step 4/5 : EXPOSE 80
---> Running in 7c1dbe18ae0f
Removing intermediate container 7c1dbe18ae0f
---> cf991d418bea
Step 5/5 : CMD ["nginx", "-g", "daemon off;"]
---> Running in 391c01904f86
Removing intermediate container 391c01904f86
---> b4386c9aefb4
Successfully built b4386c9aefb4
Successfully tagged webapp:1.0
kevin@hostos1:~/LABs$ mkdir devteam_go && cd $_
kevin@hostos1:~/LABs/devteam_go$ vi gostart.go
package main
import (
"fmt"
"os"
"log"
"net"
"net/http"
)
func gohandler(w http.ResponseWriter, r *http.Request){
name, err := os.Hostname()
if err != nil {
fmt.Printf("error: %v\n", err)
return
}
fmt.Fprintln(w, "Hostname: ", name)
addr, err := net.LookupHost(name)
if err != nil {
fmt.Printf("error: %v\n", err)
return
}
fmt.Fprintln(w, "IP: ", addr)
}
func main() {
fmt.Fprintln(os.Stdout, "Go!!! Go Application ......")
http.HandleFunc("/",gohandler)
log.Fatal(http.ListenAndServe(":9090",nil))
}
kevin@hostos1:~/LABs/devteam_go$ vi Dockerfile
FROM golang:1.15-alpine3.12 AS gobuilder-stage
MAINTAINER aramu <k0519ar@gmail.com>
LABEL "purpose"="Service Deployment using Multi-stage build."
WORKDIR /usr/src/goapp
COPY gostart.go .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /usr/local/bin/gostart
FROM scratch AS runtime-stage
COPY --from=gobuilder-stage /usr/local/bin/gostart /usr/local/bin/gostart
CMD ["/usr/local/bin/gostart"]
kevin@hostos1:~/LABs/devteam_go$ DOCKER_BUILDKIT=1 docker build -t goapp:1.0 .
kevin@hostos1:~/LABs/devteam_go$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
goapp 1.0 3f548eeaa33e About a minute ago 6.39MB
kevin@hostos1:~/LABs/devteam_go$ docker image inspect goapp:1.0
kevin@hostos1:~/LABs/devteam_go$ docker run --name goapp-deploy -p 9090:9090 -d -h goapp-container goapp:1.0
kevin@hostos1:~/LABs/devteam_go$ curl localhost:9090
Hostname: goapp-container
IP: [172.17.0.5]
작업 순서
1) "registry" image download
2) Container registry 구성
3) curl을 이용하여 접근 확인 (text based)
4) WEB UI container로 연동 (--link)
5) Private registry에 push/pull test
kevin@hostos1:~$ docker pull registry
kevin@hostos1:~$ docker pull hyper/docker-registry-web
kevin@hostos1:~$ docker images | grep registry
registry latest 3a0f7b0a13ef 5 weeks ago 24.1MB
hyper/docker-registry-web latest 0db5683824d8 5 years ago 599MB
kevin@hostos2:~$ sudo vi /etc/init.d/docker
:set nu
:31
DOCKER_OPTS=--insecure-registry 192.168.56.101:5000
sudo vi /etc/docker/daemon.json
{ "insecure-registries": ["192.168.56.101:5000"] }
sudo systemctl restart docker.service
sudo systemctl status docker.service
docker info
kevin@hostos1:~$ docker image history registry
netstat
- docker-proxy
NAT, NAPT 기능을 수행해준다.- docker-proxy 기능을 보는 방법:
ps -ef | grep PID
myweb:1.0을 pull 해오자!
kevin@hostos1:~$ docker pull ksee1230/myweb:1.0
kevin@hostos1:~$ docker image tag myweb:1.0 192.168.56.101:5000/myweb:1.0
kevin@hostos1:~$ docker image tag webapp:1.0 192.168.56.101:5000/webapp:1.0
kevin@hostos1:~$ docker image tag phpserver:1.0 192.168.56.101:5000/phpserver:1.0
kevin@hostos1:~$ docker iamge tag goapp:1.0 192.168.56.101:5000/goapp:1.0
kevin@hostos1:~$ docker images
kevin@hostos1:~$ docker push 192.168.56.101:5000/myweb:1.0
kevin@hostos1:~$ docker push 192.168.56.101:5000/phpserver:1.0
kevin@hostos1:~$ docker push 192.168.56.101:5000/goapp:1.0
kevin@hostos1:~$ curl -X GET http://192.168.56.101:5000/v2/_catalog
{"repositories":["goapp","myweb","phpserver"]}
kevin@hostos1:~$ curl -X GET http://192.168.56.101:5000/v2/myweb/tags/list
{"name":"myweb","tags":["1.0"]}
kevin@hostos1:~$ curl -X GET http://192.168.56.101:5000/v2/goapp/tags/list
{"name":"goapp","tags":["1.0"]}
docker run -itd -p 9090:8080 --name=web-registry \
-e REGISTRY_URL=http://192.168.56.101:5000/v2 \
-e REGISTRY_NAME=192.168.56.101:5000 \
--restart=always --link local-registry \
hyper/docker-registry-web
주소창에 192.168.56.101:9090
kevin@hostos1:~$ curl -XGET http://192.168.56.101:5000/v2/_catalog
kevin@hostos2:~$ curl -XGET http://192.168.56.101:5000/v2/_catalog
kevin@hostos1:~$ sudo mkdir /nexus-data
[sudo] password for kevin:
kevin@hostos1:~$ sudo chown -R kevin.kevin /nexus-data
kevin@hostos1:~$ sudo ls -l /
kevin@hostos1:~$ docker pull sonatype/nexus3
kevin@hostos1:~$ docker run -d --name=nexus-registry \
> -p 5000:5000 -p 8081:8081 \
> -v /nexus-data:/nexus-data \
> -u root \
> --restart=always \
> sonatype/nexus3
kevin@hostos1:~$ sudo cat /nexus-data/admin.password
d8208b33-61a3-4214-8b1d-32824bbaf4d5
kevin@hostos1:~$ docker login http://192.168.56.101:5000
kevin@hostos2:~$ docker tag aramu/webapp:1.0 192.168.56.101:5000/webapp:1.0
kevin@hostos2:~$ docker push 192.168.56.101:5000/webapp:1.0