Docker Flashcards

1
Q

What is the purpose of a Dockerfile?

A

It tells the Docker daemon how to create the Docker image without having to add too many flags to the docker build CLI command.

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

What is the Docker client

A

The Docker CLI, which sends it’s commands off the Docker Daemon

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

What is the Docker Daemon

A

It is the running Docker process that manages containers, images, ports and so on and handles docker CLI commands

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

What is Docker hub

A

A library of Docker images, your own, and the images that can be used as base images, for example for a node server, or a mysql server.

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

What is a Docker image?

A

A Docker image is a lightweight, standalone, executable package that includes everything needed to run a piece of software, including the code, a runtime, libraries, environment variables, and config files.

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

What is a Docker container?

A

A container is built from a created image that was built during the docker build command.

It can then be run as a container, which will execute the start up command when it starts up.

One image can be used to create multiple containers, depending on things like flags set in the docker-run command or the docker-compose file settings for container.

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

What is the purpose of a Docker Compose file

A

This file is only important in the development environment.

It tells Docker how containers (services) should communicate with each other, via exposed ports for example. Other features include volumes, which allow changes to source code files without rebuilding the image. Environment variables and specifying the dockerFile (context) is also another feature.

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

What is a docker volume

A

This is specified in the docker compose file, for a specific service (container).

It allows the developer to specify how local source code files map to files within the corresponding container. It allows changes to source code files within the host, to reflect within the container, without the need to rebuild the image. In other words, at runtime file changes are immediately available within the container.

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

What is the purpose of specifying a port in a Dockerfile by using the EXPOSE instruction?

A

It only documents the intended port, it doesn’t really expose it so it is a misnomer.

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

Explain general instruction blueprint in a Dockerfile

A

1) Use base image for example a node image
2) Copy files across
3) Run startup command

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

What is the purpose of the startup command in the Dockerfile

A

It tells the Docker daemon which command should be run in order for the container to start running the application.

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

What is the general structure of Dockerfile instructions

A

FROM node:18-alpine
WORKDIR /usr/src/app
COPY package.json package.json
COPY yarn.lock yarn.lock
RUN yarn
COPY . .
EXPOSE 1000
CMD [ “yarn” , “dev”]

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

Dockerfile vs Dockerfile.dev?

A

The one is to be used during development, and the other during deployment. The Dockerfile can be specified as a flag during the docker build command.

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

How do I build my own docker image?

A

docker build -f Dockerfile.dev -t my-second-api .

The . at the end is important

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

How do I run a built image

A

docker run -p 8080:8080 my-second-api

The port is how the container port maps to the host machine’s port.

There are other flags as well.

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

Please explain build stages

A

Within your docker file you can name a build stage, and use it’s result in a following build stage

FROM node:18-alpine AS deps-built
WORKDIR /usr/src/app
COPY ./package.json /package.json
COPY ./yarn.lock /yarn.lock
RUN yarn build

17
Q

Example of when to use build stages

A

React app

The build command creates the files in the ‘build’ directory, which is optimized, then you can install nginx and run the application.

18
Q

What is the purpose of docker-compose.yml?

A

Helps orchestration tools such as Docker Swarm.

Commonly used for local development environment, in order to start and build multiple containers at once, in order for them to communicate with each other.

19
Q

What are the most important parts of the docker-compose.yml file

A
  • The version -3
  • The services for example ui, api, db, adminer etc
  • environment variables
  • volumes
  • image name to assign to created images
  • port mapping
20
Q

What is Kubernetes?

A

It is an orchestration tool for deploying docker containers.

21
Q

What is a load balancer?

A

It sits between the client application and the servers that manage the requests sent to the backend. It distributes the load to different machines, when scaling horizontally.

22
Q

What is used to locally setup and run a Kubernetes cluster?

A

Minikube. For management of virtual machines that are used to house nodes.

23
Q

How do you run a production Kubernetes cluster

A

Managed solutions such as
AWS - Elastic Container Service with Kubernetes
Google cloud: Kubernetes Engine

24
Q

What is kubectl used for?

A

To manage containers within a node. This is local and production.

25
Q

Explain what a cluster is

A

It is a combination of nodes (VMs or servers) that house one or more containers each. The master is what the developer communicates with in order to manage the cluster. A load balancer manages the scaling of the application, horizontally.

26
Q

How do you set up local Kubernetes environment?

A

Install VirtualBox
Install Minikube
Install kubectl

27
Q

What is the purpose of Travis CI

A

It allows for publishing docker images from Github to Docker hub

27
Q

Expaln images containers and docker compose

A

docker images are built via docker build, from a dockerfile

Containers are created then either via docker-compose or docker run, with unique config.

Multiple containers can be created using an image.