07 Docker Basics
07 Docker Basics
Docker basics
• Docker is an open platform for developing, shipping, and running
applications
• Docker provides the ability to package and run an application in a loosely
isolated environment called a container
• Container are similar to virtual machines in the sense that they don’t rely on
what is installed on the host
• Containers are lightweight
• Containers are not virtual machines! – they just package everything that is
needed to run an application in to same ”package”
• All containers run on the same kernel – typically same kernel as the host
machine runs
• Linux containers on Windows and OSX run a linux kernel aside with the
main OS
Software Test Automation Ch 7 Page 2 (8)
Docker basics 15.4.2021 KRL
Docker architecture
Concepts
• An image is a read-only template with instructions for creating a Docker
container. Often, an image is based on another image, with some
additional customization.
• A container is a runnable instance of an image. You can create, start,
stop, move, or delete a container using the Docker API or CLI. You can
connect a container to one or more networks, attach storage to it, or even
create a new image based on its current state.
• By default, a container is relatively well isolated from other containers and
its host machine. You can control how isolated a container’s network,
storage, or other underlying subsystems are from other containers or from
the host machine.
• A container is defined by its image as well as any configuration options you
provide to it when you create or start it. When a container is removed,
any changes to its state that are not stored in persistent storage
disappear.
Software Test Automation Ch 7 Page 4 (8)
Docker basics 15.4.2021 KRL
Image layers
• A docker image uses layered file system
• When you make changes to files or add files they don’t replace or
overwrite existing files, the changes go to a new layer that is applied on
”top” of the previous layer
When we access a file we start from the top of the layer
• Example: stack and traverse down until we find the file. That way
we always get the most recent version of the file.
Dockerfiles
• A recipe to build an image is called dockerfile
• Example:
Base image
FROM ubuntu:xenial
RUN apt-get update && apt-get upgrade –y
RUN apt-get install gcc build-essential git gzip gawk gcc-multilib -y
Running a container
• When you run a container you need to specify
which image you want to run
• Docker then adds a read-write layer on top
of the image and makes it a runnable
container
• The original image is not modified. All
Docker hub
• When you install Docker the default registry is Docker hub
• Contains many publicly available images that you can use as starting
point
• Ubuntu is often an easy way to get started but the image is often quite
bloated – Alpine linux based image seems to be a popular minimal
image
• You can create an account which allows you to push images to hub
• For our purposes we can just pull what we need from Docker hub and
do the rest locally
Software Test Automation Ch 7 Page 8 (8)
Docker basics 15.4.2021 KRL