1
How many images are available on this host?
풀이
~ ✖ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 91ef0af61f39 4 months ago 7.79MB
nginx alpine c7b4f26a7d93 5 months ago 43.2MB
nginx latest 39286ab8a5e1 5 months ago 188MB
postgres latest b781f3a53e61 5 months ago 432MB
ubuntu latest edbfe74c41f8 5 months ago 78MB
redis latest 590b81f2fea1 6 months ago 117MB
mysql latest a82a8f162e18 6 months ago 586MB
kodekloud/simple-webapp-mysql latest 129dd9f67367 6 years ago 96.6MB
kodekloud/simple-webapp latest c6e3cd9aae36 6 years ago 84.8MB
정답
9
5
To what location within the container is the application code copied to during a Docker build?
Inspect the Dockerfile in the webapp-color directory.
풀이
COPY 명령어 뒤를 보면 된다
cat Dockerfile
FROM python:3.6
RUN pip install flask
COPY . /opt/
EXPOSE 8080
WORKDIR /opt
ENTRYPOINT ["python", "app.py"]
정답 /opt
6
When a container is created using the image built with this Dockerfile, what is the command used to RUN the application inside it.
Inspect the Dockerfile in the webapp-color directory.
풀이
일반적으로 Dockerfile 내에서 CMD나 ENTRYPOINT와 같은 지시어를 통해 정의
cat Dockerfile
FROM python:3.6
RUN pip install flask
COPY . /opt/
EXPOSE 8080
WORKDIR /opt
ENTRYPOINT ["python", "app.py"]
정답
python app.py
8
Build a docker image using the Dockerfile and name it webapp-color. No tag to be specified.
Image Name: webapp-color
정답
docker build -t webapp-color .
풀이
docker build는 Dockerfile을 기반으로 Docker 이미지를 생성하는 명령어
-t 옵션: -t는 태그를 지정하는 옵션
마침표(.)의 의미: 명령어 끝에 있는 마침표 .은 빌드 컨텍스트를 지정하는데 사용
즉, 명령어를 실행하는 위치가 Dockerfile이 있는 디렉토리여야 하고, Docker는 그 디렉토리에서 파일을 찾아서 이미지를 생성
9
Run an instance of the image webapp-color and publish port 8080 on the container to 8282 on the host.
Container with image 'webapp-color'
Container Port: 8080
Host Port: 8282

정답
docker run -p 8282:8080 webapp-color
풀이
기본적으로 docker run 뒤에는 옵션들이 먼저 오고, 그 후에 실행할 이미지가 옴 !!
docker run : Docker 컨테이너를 실행하는 명령어 -> Docker 이미지를 기반으로 컨테이너를 생성하고 실행
-p 8282:8080
-p는 포트 매핑을 설정하는 옵션 -> 컨테이너 내의 포트와 호스트(즉, 내 컴퓨터) 포트를 연결해줌
docker run -p <host_port>:<container_port> <image_name> 형식
8282:8080에서 8080은 컨테이너 내의 포트, 8282는 호스트 머신(즉, 내 컴퓨터)의 포트
이 설정은 컨테이너 안에서 8080번 포트를 사용하고 있으면, 내 컴퓨터의 8282번 포트로 그 트래픽을 전달한다는 의미
즉, 내 컴퓨터에서 8282번 포트로 접근하면 컨테이너 내부의 8080번 포트로 연결된다는 것
예를 들어, 컨테이너 안에서 웹 서버가 8080번 포트로 실행 중이라면, 이제 외부에서는 8282번 포트로 접근해서 그 웹 서버에 접속할 수 있게 됨
webapp-color : 실행할 Docker 이미지의 이름
11
What is the base Operating System used by the python:3.6 image?
If required, run an instance of the image to figure it out.
정답
docker run python:3.6 cat /etc/*release*
풀이
docker run python:3.6
cat /etc/*release*
/etc/*release*: Linux 운영 체제에서 배포판 정보를 담고 있는 파일 -> 이 파일들은 운영 체제의 이름과 버전 정보를 제공python:3.6 이미지의 기본 운영 체제가 무엇인지 확인하려면 해당 이미지가 어떤 OS를 기반으로 만들어졌는지 알아야 함 -> 이를 위해 컨테이너를 실행하고, /etc/release 파일을 확인함으로써 운영 체제 정보를 얻을 수 있음
14
Build a new smaller docker image by modifying the same Dockerfile and name it webapp-color and tag it lite.
Hint: Find a smaller base image for python:3.6. Make sure the final image is less than 150MB.
Name: webapp-color:lite
Image size less than 150MB.
정답
webapp-color on docker-images via 🐍 ➜ ls -l
total 16
-rw-r--r-- 1 root root 113 Jan 27 15:01 Dockerfile
-rw-r--r-- 1 root root 2259 Jan 27 15:01 app.py
-rw-r--r-- 1 root root 5 Jan 27 15:01 requirements.txt
drwxr-xr-x 2 root root 4096 Jan 27 15:01 templates
webapp-color on docker-images via 🐍 ➜ cat Dockerfile
FROM python:3.6
RUN pip install flask
COPY . /opt/
EXPOSE 8080
WORKDIR /opt
ENTRYPOINT ["python", "app.py"]
webapp-color on docker-images via 🐍 ➜ vi Dockerfile
webapp-color on docker-images [!] via 🐍 ➜ cat Dockerfile
FROM python:3.6-alpine
RUN pip install flask
COPY . /opt/
EXPOSE 8080
WORKDIR /opt
ENTRYPOINT ["python", "app.py"]
webapp-color on docker-images [!] via 🐍 ➜ docker build -t webapp-color:lite .
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
BuildKit is currently disabled; enable it by removing the DOCKER_BUILDKIT=0
environment-variable.
Sending build context to Docker daemon 65.02kB
Step 1/6 : FROM python:3.6-alpine
3.6-alpine: Pulling from library/python
59bf1c3509f3: Pull complete
8786870f2876: Pull complete
acb0e804800e: Pull complete
52bedcb3e853: Pull complete
b064415ed3d7: Pull complete
Digest: sha256:579978dec4602646fe1262f02b96371779bfb0294e92c91392707fa999c0c989
Status: Downloaded newer image for python:3.6-alpine
---> 3a9e80fa4606
Step 2/6 : RUN pip install flask
---> Running in 014f1b64b3d5
Collecting flask
Downloading Flask-2.0.3-py3-none-any.whl (95 kB)
Collecting Werkzeug>=2.0
Downloading Werkzeug-2.0.3-py3-none-any.whl (289 kB)
Collecting itsdangerous>=2.0
Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Collecting click>=7.1.2
Downloading click-8.0.4-py3-none-any.whl (97 kB)
Collecting Jinja2>=3.0
Downloading Jinja2-3.0.3-py3-none-any.whl (133 kB)
Collecting importlib-metadata
Downloading importlib_metadata-4.8.3-py3-none-any.whl (17 kB)
Collecting MarkupSafe>=2.0
Downloading MarkupSafe-2.0.1-cp36-cp36m-musllinux_1_1_x86_64.whl (29 kB)
Collecting dataclasses
Downloading dataclasses-0.8-py3-none-any.whl (19 kB)
Collecting typing-extensions>=3.6.4
Downloading typing_extensions-4.1.1-py3-none-any.whl (26 kB)
Collecting zipp>=0.5
Downloading zipp-3.6.0-py3-none-any.whl (5.3 kB)
Installing collected packages: zipp, typing-extensions, MarkupSafe, importlib-metadata, dataclasses, Werkzeug, Jinja2, itsdangerous, click, flask
Successfully installed Jinja2-3.0.3 MarkupSafe-2.0.1 Werkzeug-2.0.3 click-8.0.4 dataclasses-0.8 flask-2.0.3 importlib-metadata-4.8.3 itsdangerous-2.0.1 typing-extensions-4.1.1 zipp-3.6.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
---> Removed intermediate container 014f1b64b3d5
---> 45ad16ebddc2
Step 3/6 : COPY . /opt/
---> d3a849dad566
Step 4/6 : EXPOSE 8080
---> Running in acc6a7a2f7f2
---> Removed intermediate container acc6a7a2f7f2
---> f3d46c18abab
Step 5/6 : WORKDIR /opt
---> Running in c626a5d3b027
---> Removed intermediate container c626a5d3b027
---> f5172e8ddb9a
Step 6/6 : ENTRYPOINT ["python", "app.py"]
---> Running in c7527221cb96
---> Removed intermediate container c7527221cb96
---> 6f31b234921b
Successfully built 6f31b234921b
Successfully tagged webapp-color:lite
webapp-color on docker-images [!] via 🐍 ➜ docekr images
zsh: command not found: docekr
webapp-color on docker-images [!] via 🐍 ✖ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
webapp-color lite 6f31b234921b 28 seconds ago 51.9MB
webapp-color latest c1d768c76d6a 27 minutes ago 913MB
alpine latest 91ef0af61f39 4 months ago 7.79MB
nginx alpine c7b4f26a7d93 5 months ago 43.2MB
nginx latest 39286ab8a5e1 5 months ago 188MB
postgres latest b781f3a53e61 5 months ago 432MB
ubuntu latest edbfe74c41f8 5 months ago 78MB
redis latest 590b81f2fea1 6 months ago 117MB
mysql latest a82a8f162e18 6 months ago 586MB
python 3.6 54260638d07c 3 years ago 902MB
python 3.6-alpine 3a9e80fa4606 3 years ago 40.7MB
nginx 1.14-alpine 8a2fb25a19f5 5 years ago 16MB
kodekloud/simple-webapp-mysql latest 129dd9f67367 6 years ago 96.6MB
kodekloud/simple-webapp latest c6e3cd9aae36 6 years ago 84.8MB