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.