카타코더 Docker - Ignoring Files During Build

1 개요[ | ]

카타코더 Docker - Ignoring Files During Build
카타코더 Docker - Ignoring Files
카타코더 Docker
# 🔗 제목
카타코더 Docker/1 e
🡵 카타코더 Docker - Deploying Your First Docker Container
🡵 카타코더 Docker - Deploy Static HTML Website as Container
🡵 카타코더 Docker - Building Container Images
🡵 카타코더 Docker - Dockerizing Node.js
🡵 카타코더 Docker - Optimise Builds With Docker OnBuild
🡵 카타코더 Docker - Ignoring Files During Build
🡵 카타코더 Docker - Create Data Containers
🡵 카타코더 Docker - Creating Networks Between Containers using Links
🡵 카타코더 Docker - Creating Networks Between Containers using Networks
🡵 카타코더 Docker - Persisting Data Using Volumes

2 Docker Ignore[ | ]

2.1 Example[ | ]

$ ll
total 20
drwxr-xr-x 1 scrapbook scrapbook 4096 Mar 23 02:22 ./
drwxr-xr-x 1 scrapbook scrapbook 4096 Jul  2  2018 ../
-rw-r--r-- 1 root      root        71 Mar 23 02:22 Dockerfile
-rwxr-xr-x 1 root      root        19 Mar 23 02:22 cmd.sh*
-rw-r--r-- 1 root      root        12 Mar 23 02:22 passwords.txt
$ cat cmd.sh
echo "Hello World"
$ cat passwords.txt
admin:admin
$ cat Dockerfile
FROM alpine
ADD . /app
COPY cmd.sh /cmd.sh
CMD ["sh", "-c", "/cmd.sh"]
$ docker build -t password .
Sending build context to Docker daemon  4.096kB
Step 1/4 : FROM alpine
 ---> 11cd0b38bc3c
Step 2/4 : ADD . /app
 ---> d31fbaa6996a
Step 3/4 : COPY cmd.sh /cmd.sh
docker run password ls /app
 ---> e5c5d68e59d5
Step 4/4 : CMD ["sh", "-c", "/cmd.sh"]
 ---> Running in a603c7518ea3
Removing intermediate container a603c7518ea3
 ---> 7dfcee3eff6e
Successfully built 7dfcee3eff6e
Successfully tagged password:latest
$ docker run password ls /app
Dockerfile
cmd.sh
passwords.txt

2.2 Ignore File[ | ]

$ echo passwords.txt >> .dockerignore
$ cat .dockerignore
passwords.txt
$ docker build -t nopassword .
Sending build context to Docker daemon  4.096kB
Step 1/4 : FROM alpine
 ---> 11cd0b38bc3c
Step 2/4 : ADD . /app
 ---> 84b3f01f9053
Step 3/4 : COPY cmd.sh /cmd.sh
 ---> 14d22649464f
Step 4/4 : CMD ["sh", "-c", "/cmd.sh"]
 ---> Running in fb2ebff22d16
Removing intermediate container [fb2ebff22d16
 ---> 3ce325bc0f4d
Successfully built 3ce325bc0f4d
Successfully tagged nopassword:latest
$ docker run nopassword ls /app
Dockerfile
cmd.sh

3 Docker Build Context[ | ]

$ fallocate -l 100M big-temp-file.img
$ ll
total 102424
drwxr-xr-x 1 scrapbook scrapbook      4096 Mar 23 02:31 ./
drwxr-xr-x 1 scrapbook scrapbook      4096 Jul  2  2018 ../
-rw-r--r-- 1 root      root             14 Mar 23 02:27 .dockerignore
-rw-r--r-- 1 root      root             71 Mar 23 02:27 Dockerfile
-rw-r--r-- 1 root      root      104857600 Mar 23 02:27 big-temp-file.img
-rwxr-xr-x 1 root      root             19 Mar 23 02:27 cmd.sh*
-rw-r--r-- 1 root      root             12 Mar 23 02:27 passwords.txt
$ docker build -t large-file-context .
Sending build context to Docker daemon  104.9MB
Step 1/4 : FROM alpine
 ---> 11cd0b38bc3c
Step 2/4 : ADD . /app
 ---> c10afa9a8e10
Step 3/4 : COPY cmd.sh /cmd.sh
 ---> b8a96be12b99
Step 4/4 : CMD ["sh", "-c", "/cmd.sh"]
 ---> Running in 66eb59e66fe7
Removing intermediate container 66eb59e66fe7
 ---> 5b9fb701a647
Successfully built 5b9fb701a647
Successfully tagged large-file-context:latest
$ docker images large-file-context
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
large-file-context   latest              5b9fb701a647        2 minutes ago       109MB

4 Optimised Build[ | ]

$ echo big-temp-file.img >> .dockerignore
$ cat .dockerignore
passwords.txt
big-temp-file.img
$ docker build -t no-large-file-context .
Sending build context to Docker daemon  4.096kB
Step 1/4 : FROM alpine
 ---> 11cd0b38bc3c
Step 2/4 : ADD . /app
 ---> 82518f82a9e9
Step 3/4 : COPY cmd.sh /cmd.sh
 ---> bbe5e2b4a067
Step 4/4 : CMD ["sh", "-c", "/cmd.sh"]
 ---> Running in f5a93512cc2a
Removing intermediate container f5a93512cc2a
 ---> bdff8dcc3c5b
Successfully built bdff8dcc3c5b
Successfully tagged no-large-file-context:latest
$ docker images no-large-file-context
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
no-large-file-context   latest              bdff8dcc3c5b        28 seconds ago      4.41MB

5 같이 보기[ | ]

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