chapter 3 Flashcards

1
Q

Describe the ways to make a Container Image: from a Dockerfile or from Instance Promotion

A

Instance promotion:
Grab the image ubuntu and run an interactive shell in a ubuntu container -> docker run -it ubuntu bash
Here you can install packages for example figlet -> apt-get update, apt-get install -y figlet
Now exit the container -> exit
We need to get the id of the container -> docker ps -a
Docker commit (container id)
Check if the image was made successfully -> docker image ls
Give your container a name -> copy image id -> docker image ls -> docker image tag (image id) (name)

Dockerfile:
Create dockerfile -> from ubuntu, run apt-get update && apt-get install -y figlet
Docker build -t (name) .
Docker run (name) figlet hello

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain the different keywords in a Dockerfile: FROM, RUN, COPY, WORKDIR, CMD, EXPOSE

A

From = specifies the base image to use as the starting point
Run = execute a command in the image
Copy = copies file from the current directory of the docker host into the image
Workdir = sets the working directory for the image
Cmd = specifies what command to run when a container is started from the image
Expose = documents which ports the application uses but does not actually expose any ports

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe how image layers and caching work and contribute during the Docker build process

A

Image layers: when running images we build with docker they appear to be a single OS and application but the images themselves are actually built in layers. All the commands in a dockerfile are separated into layers

Caching = these layers are cached and can be recognized by docker

Contributing = if we build an image and after that add a extra line of code, docker recognizes that we had already built some of these layers and since nothing changed in those layers it could simply use a cached version of the layer, rather than pulling down code a second time and running those steps so it only affects a single layerle layer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly