Docker Flashcards
What is the purpose of a Dockerfile?
It tells the Docker daemon how to create the Docker image without having to add too many flags to the docker build
CLI command.
What is the Docker client
The Docker CLI, which sends it’s commands off the Docker Daemon
What is the Docker Daemon
It is the running Docker process that manages containers, images, ports and so on and handles docker CLI commands
What is Docker hub
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.
What is a Docker image?
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.
What is a Docker container?
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.
What is the purpose of a Docker Compose file
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.
What is a docker volume
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.
What is the purpose of specifying a port in a Dockerfile by using the EXPOSE instruction?
It only documents the intended port, it doesn’t really expose it so it is a misnomer.
Explain general instruction blueprint in a Dockerfile
1) Use base image for example a node image
2) Copy files across
3) Run startup command
What is the purpose of the startup command in the Dockerfile
It tells the Docker daemon which command should be run in order for the container to start running the application.
What is the general structure of Dockerfile instructions
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”]
Dockerfile vs Dockerfile.dev?
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 do I build my own docker image?
docker build -f Dockerfile.dev -t my-second-api .
The . at the end is important
How do I run a built image
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.
Please explain build stages
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
Example of when to use build stages
React app
The build command creates the files in the ‘build’ directory, which is optimized, then you can install nginx and run the application.
What is the purpose of docker-compose.yml?
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.
What are the most important parts of the docker-compose.yml file
- The version -3
- The services for example ui, api, db, adminer etc
- environment variables
- volumes
- image name to assign to created images
- port mapping
What is Kubernetes?
It is an orchestration tool for deploying docker containers.
What is a load balancer?
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.
What is used to locally setup and run a Kubernetes cluster?
Minikube. For management of virtual machines that are used to house nodes.
How do you run a production Kubernetes cluster
Managed solutions such as
AWS - Elastic Container Service with Kubernetes
Google cloud: Kubernetes Engine
What is kubectl used for?
To manage containers within a node. This is local and production.
Explain what a cluster is
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.
How do you set up local Kubernetes environment?
Install VirtualBox
Install Minikube
Install kubectl
What is the purpose of Travis CI
It allows for publishing docker images from Github to Docker hub
Expaln images containers and docker compose
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.