Containerization Flashcards
What is the purpose of containers?
- Isolate software from its surroundings, for example differences between development and staging environments.
- Help reduce conflicts between teams running different software on the same infrastructure.
How to configure a Docker container?
- Create a docker-compose.yml file at the root of a project.
- This YAML file defines how containers should behave in production.
- It should specifies the compose file format (or version), the services, networks and volumes.
Start a docker container.
$ docker-compose up
Shorthand for $ docker-compose build && docker-compose run
How to run docker commands without putting a sudo in front of them?
Add username to docker group.
What is containerization?
The process of distributing and deploying apps in a portable and predictable way. It accomplishes this by packaging components and their dependencies into standardized, isolated, lightweight process environments called containers.
Describe the docker compose workflow.
- Define each service in a dockerfile.
- Define the services and their relation to each other in the docker-compose.yml file.
- Use docker-compose up to start the system.
List the running docker containers.
$ docker-compose ps
What are the main functions of docker compose?
- Main: creation of microservice architecture (i.e. containers and the links between them).
- Building images (if an appropriate dockerfile is provided).
- Scaling containers running a given service.
- Healing: re-running containers that have stopped.
What is a container?
A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings.
Differences between containers and VMs.
Containers:
- Abstraction of the app layer that packages code and dependencies together.
- Multiple containers can run on the same machine, sharing the OS kernel and running as isloated processes.
- Containers take up less space than VMs (~10 MBs) and start almost instantly.
VMs:
- Abstraction of physical hardware turning one server into many.
- Hypervisor allows multiple VMs to run on a signle machine.
- Each VM includes a full copy of an OS, apps, binaries and libraries.
- VMs takes more space (~10 GBs) and are slow to boot.
What is a dockerfile?
A dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.
List local docker images and inspect them.
$ docker image ls
$ docker inspect [id]
Run services in the background with docker.
$ docker-compose up -d
Explanation of -d: “detached mode”
Run one-off commands for services with docker-compose.
$ docker-compose run [service] [command]
Stop services with docker-compose.
$ docker-compose stop