카타코더 Docker - Building Container Images

1 개요

틀:Katacoda

2 Creating a Dockerfile

index.html
<h1>Hello World</h1>
Dockerfile
FROM nginx:1.11-alpine
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

3 Building Containers

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
$ docker build -t nginx .
Sending build context to Docker daemon  3.072kB
Step 1/4 : FROM nginx:1.11-alpine
1.11-alpine: Pulling from library/nginx
709515475419: Pull complete
4b21d71b440a: Pull complete
c92260fe6357: Pull complete
ed383a1b82df: Pull complete
Digest: sha256:5aadb68304a38a8e2719605e4e180413f390cd6647602bee9bdedd59753c3590
Status: Downloaded newer image for nginx:1.11-alpine
 ---> bedece1f06cc
Step 2/4 : COPY index.html /usr/share/nginx/html/index.html
 ---> ff82266f8a3c
Step 3/4 : EXPOSE 80
 ---> Running in 75539b6235b5
Removing intermediate container 75539b6235b5
 ---> b06ce6726b2a
Step 4/4 : CMD ["nginx", "-g", "daemon off;"]
 ---> Running in df877b3d066b
Removing intermediate container df877b3d066b
 ---> a2272ce5f857
Successfully built a2272ce5f857
Successfully tagged nginx:latest
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              a2272ce5f857        7 seconds ago       54.3MB
nginx               1.11-alpine         bedece1f06cc        23 months ago       54.3MB

4 Launching New Image

$ docker run -d -p 80:80 nginx
45afb3ea6530661117140229e1959133552d8d31c45cfa72d27b957c6444d0a6
$ curl -i http://docker
HTTP/1.1 200 OK
Server: nginx/1.11.13
Date: Fri, 22 Mar 2019 15:08:40 GMT
Content-Type: text/html
Content-Length: 21
Last-Modified: Fri, 22 Mar 2019 14:57:48 GMT
Connection: keep-alive
ETag: "5c94f7ec-15"
Accept-Ranges: bytes

<h1>Hello World</h1>
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS      PORTS                         NAMES
45afb3ea6530        nginx               "nginx -g 'daemon of…"   47 seconds ago      Up 45 seconds      0.0.0.0:80->80/tcp, 443/tcp   boring_kare

5 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}