Dockers Containers in action Slide 0 to hero

TayyabAslam24 25 views 37 slides May 01, 2024
Slide 1
Slide 1 of 37
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37

About This Presentation

Devops


Slide Content

Docker

What is Docker?

Duckietown
I got it, it is like VirtualBox…. Hem, not really!
3
•Docker is similar (in spirit) to Virtual Environments but at a File System level
VM 1 VM 2 VM 3
Container1Container2Container3

Why Docker?

Duckietown
Common scenario
•You just started a new research project

1.Freshly install Ubuntu for a clean environment

2.Configure your environment

3.Install all the libraries you need

5
ubuntu:18.04
NAME=Andrea
apt install python-numpy
#
>
>

Duckietown
Common scenario (with Docker)
•You just started a new research project

1.Freshly install Ubuntu for a clean environment

2.Configure your environment

3.Install all the libraries you need

6
ubuntu:18.04
NAME=Andrea
apt install python-numpy
FROM
ENV
RUN
Docker2ile

Duckietown
Docker = A lot of new confusing terms…
7
For example:
•Docker Layer
•Docker Image
•Docker Container
•Docker Volume
•Docker Registry
•Docker Compose

Docker
Layer/Image/File

Duckietown
Docker Layer
•It is a collection of files
•e.g.,
/my_file.dat (user file)
/etc/hosts (system file)
•It is uniquely identified by an hash
sha256:94c5c6f50a7204b49c5cdfd662aa203f3af0b2e2eb6b449634738edfae77fbe3
9

Duckietown
Docker Image
•It is the combination of a sequence of Docker Layers
•It is uniquely identified by an hash
sha256:3448a24e6db0125ebbafefee0a355232fc533bd3a68c89dab3d450a8fa15d8ed
•It is also (non-uniquely) identified by a name
library/ubuntu:18.04
afdaniele/compose:0.9
format:
[owner] / [image] : [tag]
library / [image] : latest (default)
10

Duckietown
Docker Image VS Docker Layers
•You CANNOT create single layers
•You CAN create new images
•Layers are read-only
•The simplest (most beautiful) way to create an image is a Dockerfile
11

Duckietown
Dockerfile (an example)
12
FROM python:3.6
MAINTAINER Andrea F. Daniele <[email protected]>
RUN pip3 install tensorflow
VOLUME /tflog
EXPOSE 6006/tcp
CMD ["python3", "-m", “tensorflow.tensorboard", "--logdir=/tflog" ]

Duckietown
Dockerfile - Instructions
13
FROM
ARG
ENV
MAINTAINER
WORKDIR
USER
RUN
ADD
COPY
VOLUME
EXPOSE
CMD
ENTRYPOINT
Define the base image
Define build-only arguments (non-persistent)
Define environment variables (persistent)
Set maintainer info
Set working directory
Set user ID
Run a command inside a container
Copy files and directories from the build context
Copy files and directories from the build context
Define a new volume
Declare ports used by the image
Define default command
Define entrypoint executable
Useful documentation: docs.docker.com/reference

Duckietown
Docker Image
14
FROM python:3.6
MAINTAINER Andrea F. Daniele <[email protected]>
RUN pip3 install tensorflow
VOLUME /tflog
...
EXPOSE 6006/tcp
CMD ["python3", "-m", “tensorflow.tensorboard", "--logdir=/tflog" ]
Docker'ile
python : 3.6
afdaniele / tensor2low
intermediate layers

Building an Image

Duckietown
Directory
Build Context
16
FROM python:3.6
...
COPY my_image.jpg /data/my_image.jpg
...
Docker'ile
•A directory from which Docker is allowed to copy files to a layer

Duckietown
Building a Docker Image (using Dockerfile)
•Build an image from a Dockerfile and a Build Context
17
docker build -t my_image [-f Dockerfile] ./>
Image name Docker2ile pathBuild context
Docker'il
e
Build context
Docker Engine Docker Image

Docker Container

Duckietown
Docker Container
•An instance of a Docker image
•It is uniquely identified by an alphanumeric string. e.g.,
94c5c6f50a7204b49c5cdfd662aa203f3af0b2e2eb6b449634738edfae77fbe3
•It is also assigned a (possibly custom) name. e.g.,
admiring_einstein
my_website
19
docker run [options] my_image>
•Run a container from an image
Image name

Duckietown
Docker Container
20
python : 3.6
afdaniele / tensor2low
volatile (writeable) layer
docker run [options] my_image>
•Run a container from an image
Image name
•Contains everything you do in a running container
•Is lost when the container is deleted

Duckietown
Combining layers - AUFS FileSystem
Advanced multi-layered Unification File System
21
Another Unification File System
•Later revised to,
•Originally meaning,

Data Persistency

Duckietown
Data persistency - Mounting directories
•You can share local directories with one or more containers using
where,
path to a directory in the host file system
destination path to the directory in the container file system
23
docker run -v [local_dir]:[container_dir] my_image>
local_dir
container_dir

Duckietown
Data persistency - Docker Volumes
•Create a Docker volume
•You can attach a volume to a container using
where,
name of the volume
destination path in the container file system
24
docker volume create [volume_name]>
volume_name
container_dir
docker run -v [volume_name]:[container_dir] my_image>

Duckietown
Docker Container (an interesting one)
•Running the Dashboard on a Duckiebot
25
docker run
-it
-p 8080:80/tcp
-v compose-data:/var/www/html
-v /data:/data
--hostname $(hostname)
--name dashboard
duckietown/dt-duckiebot-dashboard:daffy
>
docker volume create compose-data>

Duckietown
Dockerfile, Docker Image and Docker Container
26

Docker Registry

Duckietown
Docker Registry
•A storage and distribution system for Docker images
•Two fundamental operations: push and pull
28

Docker Compose

Duckietown
80 / tcp
backups
db-storage
mysql-dbweb-server
version: '2'
services:
mysql-db:
image: mysql:latest
volumes:
- db-storage:/var/lib/mysql
- backups:/backups
web-server:
image: apache:latest
ports:
- "80:80"
links:
- mysql-db:mysql.db
environment:
- DBHost=mysql.db
- DBUser=my_user
- DBPassword=my_password
volumes:
db-storage:
backups:
docker-compose.yaml
Docker Compose
•An application can be split across multiple Docker images
•The application runs when all the corresponding containers run

Docker in Duckietown

Duckietown 32
Duckietown
The Docker images family tree

Duckietown
Duckiebot Pipeline
33

Duckietown
Duckiebot Pipeline
34
dt-duckiebot-interface
•left/right wheel speed
•raw camera image
•leds color and pattern

Duckietown
Duckiebot Pipeline
35
dt-duckiebot-interface
•left/right wheel speed
•raw camera image
•led color and pattern
dt-car-interface
•linear/angular velocity

Duckietown
Duckiebot Pipeline
36
dt-duckiebot-interface
•left/right wheel speed
•raw camera image
•led color and pattern
dt-car-interface
•linear/angular velocity
dt-core
•lane following
•coordination
•…

Duckietown
What’s nice about Docker
•Dockerfiles serve as (required) documentation
•Full control over execution environment
•Know exactly what the dependencies are (e.g., dependencies-apt.txt)
•Know exactly what files your application needs (build context, docker diff)
•Full support of cross-application interaction
•e.g., ROS, LCM
•No conflict between libraries
•Full control over networks and ports
•Open only the ports and for the protocols you need
•Full control over resources (X-Server, CPU, GPU, RAM)
37