tonykang22 / study

0 stars 0 forks source link

[Docker & K8S] 09. 도커 컨테이너 다루기 - 이미지 빌드 #70

Open callmeaxxe opened 2 years ago

callmeaxxe commented 2 years ago

09. 도커 컨테이너 다루기 - 이미지 빌드

도커 이미지 구조

image

root@mobius-pub:~/docker# docker images
REPOSITORY                           TAG                        IMAGE ID       CREATED        SIZE
mysql                                5.7                        a3d35804fa37   12 days ago    462MB
grafana/grafana                      latest                     c876b1dbac21   2 weeks ago    286MB
ubuntu                               focal                      53df61775e88   3 weeks ago    72.8MB
nginx                                latest                     fa5269854a5e   4 weeks ago    142MB
mariadb                              10.7                       100166b773f8   6 weeks ago    414MB
wordpress                            5.9.1-php8.1-apache        00b929d62f80   2 months ago   612MB
gcr.io/k8s-minikube/kicbase-builds   v0.0.29-1644344181-13531   1312ccd2422d   3 months ago   1.14GB
gcr.io/k8s-minikube/kicbase          v0.0.30                    1312ccd2422d   3 months ago   1.14GB
root@mobius-pub:~/docker#
root@mobius-pub:~/docker# docker image inspect nginx:latest
[
    {
        ...
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:9c1b6dd6c1e6be9fdd2b1987783824670d3b0dd7ae8ad6f57dc3cea5739ac71e",
                "sha256:4b7fffa0f0a4a72b2f901c584c1d4ffb67cce7f033cc7969ee7713995c4d2610",
                "sha256:f5ab86d69014270bcf4d5ce819b9f5c882b35527924ffdd11fecf0fc0dde81a4",
                "sha256:c876aa251c80272eb01eec011d50650e1b8af494149696b80a606bbeccf03d68",
                "sha256:7046505147d7f3edbf7c50c02e697d5450a2eebe5119b62b7362b10662899d85",
                "sha256:b6812e8d56d65d296e21a639b786e7e793e8b969bd2b109fd172646ce5ebe951"
            ]
        },
        ...
    }
]

Dockerfile 없이 이미지 생성

 # docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] 
# ubuntu 컨테이너의 현재 상태를 my_ubuntu:v1 이미지로 생성
$ docker commit -a fastcampus -m “First Commit” ubuntu my_ubuntu:v1
root@mobius-pub:~/docker# docker commit -a fastcampus -m "Add my_file" my_ubuntu my_ubuntu:v1
sha256:222ffd4d4e5ac65082c08bc7e59ed85f769a4a0f3b4f5aa5f59a1410ef1c901b
root@mobius-pub:~/docker# docker images
REPOSITORY                           TAG                        IMAGE ID       CREATED              SIZE
my_ubuntu                            v1                         222ffd4d4e5a   About a minute ago   72.8MB
...

Dockerfile 이용하여 이미지 생성

FROM node:12-alpine
RUN apk add --no-cache python3 g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
 # docker build [OPTIONS] PATH
# ./ 디렉토리를 빌드 컨텍스트로 my_app:v1 이미지 빌드 (Dockerfile 이용)
$ docker build -t my_app:v1 ./
# ./ 디렉토리를 빌드 컨텍스트로 my_app:v1 이미지 빌드 (example/MyDockerfile 이용)
$ docker build -t my_app:v1 -f example/MyDockerfile ./

빌드 컨텍스트

=> [internal] load build definition from Dockerfile                          0.0s
  => => transferring dockerfile: 190B                                          0.0s
  => [internal] load .dockerignore                                             0.0s
  => => transferring context: 2B                                               0.0s
  => [internal] load metadata for docker.io/library/node:12-alpine             1.0s
  => [1/5] FROM docker.io/library/node:12-alpine@sha256:0eca266c5fe38ba93aeba  0.0s
 => [internal] load build context
=> => transferring context: 4.61MB
0.1s 0.1s

.dockerignore

*.md !README.md