Docker
Docker
Docker
What is Docker?
I got it, it is like VirtualBox…. Hem, not really!
VM 1 VM 2 VM 3
• Docker is similar (in spirit) to Virtual Environments but at a File System level
Duckietown 3
Why Docker?
Common scenario
3. Install all the libraries you need > apt install python-numpy
Duckietown 5
Common scenario (with Docker)
3. Install all the libraries you need RUN apt install python-numpy
Duckietown 6
Docker = A lot of new confusing terms…
For example:
• Docker Layer
• Docker Image
• Docker Container
• Docker Volume
• Docker Registry
• Docker Compose
Duckietown 7
Docker
Layer/Image/File
Docker Layer
• It is a collection of files
• e.g.,
/my_file.dat (user file)
/etc/hosts (system file)
Duckietown 9
Docker Image
format:
[owner] / [image] : [tag]
Duckietown 10
Docker Image VS Docker Layers
Duckietown 11
Dockerfile (an example)
FROM python:3.6
VOLUME /tflog
EXPOSE 6006/tcp
Duckietown 12
Dockerfile - Instructions
FROM Define the base image
ARG Define build-only arguments (non-persistent)
ENV Define environment variables (persistent)
MAINTAINER Set maintainer info
WORKDIR Set working directory
USER Set user ID
RUN Run a command inside a container
ADD Copy files and directories from the build context
COPY Copy files and directories from the build context
VOLUME Define a new volume
EXPOSE Declare ports used by the image
CMD Define default command
ENTRYPOINT Define entrypoint executable
Duckietown 13
Docker Image
afdaniele / tensor2low
intermediate layers
python : 3.6
Docker'ile
FROM python:3.6
VOLUME /tflog
...
EXPOSE 6006/tcp
Duckietown 14
Building an Image
Build Context
• A directory from which Docker is allowed to copy files to a layer
Directory
Docker'ile
FROM python:3.6
...
...
Duckietown 16
Building a Docker Image (using Dockerfile)
Docker'il
e
Build context
Duckietown 17
Docker Container
Docker Container
Image name
Duckietown 19
Docker Container
afdaniele / tensor2low
python : 3.6
Image name
Duckietown 20
Combining layers - AUFS FileSystem
• Originally meaning,
Another Unification File System
Duckietown 21
Data Persistency
Data persistency - Mounting directories
• You can share local directories with one or more containers using
where,
Duckietown 23
Data persistency - Docker Volumes
where,
Duckietown 24
Docker Container (an interesting one)
Duckietown 25
Dockerfile, Docker Image and Docker Container
Duckietown 26
Docker Registry
Docker Registry
Duckietown 28
Docker Compose
Docker Compose
• An application can be split across multiple Docker images
• The application runs when all the corresponding containers run
docker-compose.yaml
version: '2'
services:
mysql-db:
web-server:
80 / tcp
image: apache:latest
db-storage
ports:
- "80:80"
links:
- mysql-db:mysql.db
environment:
- DBHost=mysql.db
- DBUser=my_user
- DBPassword=my_password
volumes:
db-storage:
backups:
Duckietown
Docker in Duckietown
The Docker images family tree
Duckietown
Duckietown 32
Duckiebot Pipeline
Duckietown 33
Duckiebot Pipeline
dt-duckiebot-interface
Duckietown 34
Duckiebot Pipeline
dt-duckiebot-interface
dt-car-interface
• linear/angular velocity
Duckietown 35
Duckiebot Pipeline
dt-duckiebot-interface
dt-car-interface
• linear/angular velocity
dt-core
• lane following
• coordination
• …
Duckietown 36
What’s nice about Docker
• Know exactly what files your application needs (build context, docker diff)
• Open only the ports and for the protocols you need
Duckietown 37