Section 3: Building Custom Images through Docker Server Flashcards

1
Q

What are the steps to create a docker file?

A

Specify a base image -> Run commands to install additional programs -> Specify command to run on container startup

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

What is a docker file?

What is it used for?

A

A docker file is a plain text file that is used to have config details of how the docker should behave.

It’s used to create an image of a docker and it specifies the config details as mentioned before. The steps to create an usable image is as below:
Docker File -> Docker Client -> Docker Server -> Usabe Image.

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

What are the processes involved in creating a docker image?

A

We create a docker file - Dockerfile and specify the above commands shown in the picture.
After constructing the dockerfile we give the command “docker build .” in the directory path and build the docker image.
. in docker build is used to give build context - That is details on the configuration files we will include in building the image.

Explanation of the build steps above in detail:

FROM alpine
The docker daemon checks if we have any built docker image in the cache. Else it fetches the image from docker hub. Now a fresh alpine image is available.
RUN apk add –update redis
Now a temporary container is created in this step using the image retrieved in the previous step. And apk add –update redis is run as the primary running process on that temporary container and the redis package is stored in the hard drive space of the container.
Note: apk is a package manager in alpine OS.

A file system snapshot of this container is taken, stored and the container is removed.
CMD [“redis-server”]
In this step again a temporary container is created using the image built in the previous step. And the primary running process is set as “redis-server” and a snapshot of this container’s FS and running command is taken and the image is stored. The container is removed.
Note: Only the primary running command is set, it’s not executed.

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

How do you tag an image that is created?

A

We can tag an image by using the convention:

dockerid/projectname:version

e.g. kashyapsiva/redis:latest

While referencing the image you don’t have to mention the tag as above. You can ignore the :latest to create a container from the image.

The entire command would be:

docker build -t dockerid/projectname:version .

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