docker - developer.ridgerun.com€¦ · docker is 7 a technology that enables the management and...
TRANSCRIPT
![Page 1: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/1.jpg)
dockerridgerun 2020
1
![Page 2: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/2.jpg)
developers love docker
2
![Page 3: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/3.jpg)
companies love docker
3
![Page 4: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/4.jpg)
so......what is docker useful for?
4
![Page 5: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/5.jpg)
you......tell me at the end of the slides.
5
![Page 6: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/6.jpg)
docker
6
![Page 7: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/7.jpg)
docker is
7
● A technology that enables the management and use of containers.
● A set of tools to architect applications and services.
● An ecosystem to share and collaborate with other developers.
![Page 8: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/8.jpg)
containers are
8
● A technology that allows you to package and isolate applications with their entire runtime.
● Not virtual machines.
● Built on top of the host operating system and kernel.
![Page 9: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/9.jpg)
comparison
9
Containers
● Less overhead● Share host OS kernel● Virtualize using software runtimes● Only the FS experience
Virtual Machines
● More overhead● Provide their own kernel● May use hardware to virtualize● Full machine experience
![Page 10: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/10.jpg)
containers already existed
10
● LXC (Linux Containers) is the most
obvious example.
● LXC provide a more OS like
experience
● Docker is single-app by default (i.e.:
no proper init).
● Docker is much more user friendly.
![Page 11: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/11.jpg)
docker lifecycle
11
![Page 12: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/12.jpg)
docker lifecycle 12
use saveinstall create delete
![Page 13: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/13.jpg)
docker lifecycle 13
use saveinstall create delete
![Page 14: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/14.jpg)
docker
installFull instructions:
https://docs.docker.com/install/linux/docker-ce/ubuntu/
Other architectures available!
14
# Uninstall old versionssudo apt remove docker docker-engine docker.io containerd runc
# Install dependenciessudo apt updatesudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
# Install GPG Keycurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# Add Docker PPAsudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# Finally installsudo apt updatesudo apt install docker-ce docker-ce-cli containerd.io
![Page 15: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/15.jpg)
dockerinstall
Running as non-root user.
Full instructions at:
https://docs.docker.com/install/linux/linux-postinstall/
Under your own risk!
15
# Create the docker groupsudo groupadd docker
# Add yourself to the groupsudo usermod -aG docker $USER
# To avoid re-loggingnewgrp docker
# Test proper installationdocker ps
![Page 16: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/16.jpg)
installOther operating systems.
16
Docker for Mac
Docker for Windows
![Page 17: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/17.jpg)
docker
installSome useful tips.
17
# List commandsdocker help
# Specific command helpdocker create --help
# Print versiondocker version
![Page 18: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/18.jpg)
docker lifecycle 18
use saveinstall create delete
![Page 19: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/19.jpg)
createContainers are created from
19
registry
computer
container
images
PULLS
CREATES
![Page 20: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/20.jpg)
createYou refer to images by their name.
Image names convey a lot of information.
We use defaults most of the times.
20
Portion Description
1 Registry hostname to pull image from. If omitted defaults to the official Docker hub.
2 Account hosting the image. Not needed for official docker images.
3 Image name. The only mandatory parameter.
4 Tag or version. If omitted, the "latest" tag will be used. This is not necessary the most recent!
dockerhub.cr.ridgerun.com:5000/ridgerun/ubuntu:16.04
![Page 21: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/21.jpg)
docker
createCreate a new container!
You need a base image
List of public images:
https://hub.docker.com/search/?type=image
When do you omit -t and -i?
21
# Create the containerdocker create -ti --name mycontainer ubuntu:18.04
Parameter Description
-i Read STDIN (input)
-t Attach a pseudo-terminal (interaction)
--name mycontainer Custom name of the container
ubuntu Image
18.04 Tag name (version). Defaults to "latest"
![Page 22: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/22.jpg)
docker
createShare data between host and container
Absolute paths share dirs or files
Relative create new volumes
Useful for devices, for example.
22
# Share dir: /home/mgruner (host) in /host (container)docker create -ti -v /home/mgruner/:/host ubuntu:18.04
# Share file: /home/mgruner/file.txt (host) in /host.txt (container)docker create -ti -v /home/mgruner/file.txt:/host.txt ubuntu:18.04
# Create a persistent volumedocker create -ti -v myvolume:/host ubuntu:18.04
![Page 23: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/23.jpg)
createOther useful options
Make sure you list all options using docker create --help
23
Parameter Description
--memory , -m Memory limit (bytes), i.e: 1024, 1M, 1G
--cpus CPU percentage to use, i.e: 1, 1.5
--restart Auto-restart: no, on-failure, always, unless-stopped
--rm Remove container after stop
--env, -e Define environment variables, i.e: A=a
![Page 24: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/24.jpg)
docker
createSome useful tips
24
# List existing containers (started)docker ps
# List existing containers (all)docker ps -a
# Get container info (IP address, for example)docker inspect mycontainer
![Page 25: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/25.jpg)
docker lifecycle 25
use saveinstall create delete
![Page 26: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/26.jpg)
docker
useTime to execute and use the container.
Containers need to be started.
Bash is a usual command for interaction.
You may use any command.
Stop your container afterwards.
Nothing will be erased.
26
# Start the containerdocker start mycontainer
# Get into the containerdocker exec -ti mycontainer bash
# Stop the containerdocker stop mycontainer
![Page 27: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/27.jpg)
dockeruseUsual initial needed work
Note that you are root!
You have absolutely nothing in your container.
27
# Get into the containerdocker start mycontainerdocker exec -ti mycontainer bash
container
# Load up the apt cachesapt update
# Install common packagesapt install git build-essential autoconf libtool autotools
![Page 28: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/28.jpg)
useSSH is a very common use case
SSH needs to be manually started
I recommend creating a user
Practice connecting to the container!
How can you get the IP?
28
container
# Install sshd and sudo for your new userapt install sudo openssh-server
# Create new useradduser ridgerun
# Give it root accessadduser ridgerun sudo
# Manually start ssh server (every time container is started)service ssh start
# Exit the containerexit
![Page 29: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/29.jpg)
docker
useWhat about long running processes?
You may detach the container.
Processes will continue to run.
Reattach later!
29
# Option 1: detach from executiondocker exec -d -ti mycontainer /run_long_process.sh
container
# Option 2: detach from container ./run_long_process.sh
# Now press ctrl+p ctrl+q to detach
docker
# Reattach to the containerdocker attach mycontainer
![Page 30: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/30.jpg)
docker lifecycle 30
use saveinstall create delete
![Page 31: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/31.jpg)
docker
saveYou just spent hours in a perfect container!
You can save the current state into an image.
You can create new containers from this image.
The image is a snapshot of the container.
31
# Save an image based on a containerdocker commit \ -a "Michael Gruner <[email protected]>" \ -m "Example container" mycontainer \ myimage:mytag
# Create a new container from you newly created image!docker create -ti --name newcontainer myimage:mytag
![Page 32: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/32.jpg)
docker
saveTags serve as an alias to an image.
You can rename images using aliases.
32
# Save an image based on a containerdocker tag myimage:mytag newimage:newtag
# List existing imagesdocker images
# Alternative way to list imagesdocker image ls
![Page 33: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/33.jpg)
dockersave
Here's how you interact with images.
33
# Remove an existing imagedocker image rm newimage:newtag
# Remove all unused imagesdocker image prune
# Save an image to share itdocker save myimage:mytag | gzip > myimage_mytag.tar.gz
# Load a shared imagedocker load < myimage_mytag.tar.gz
![Page 34: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/34.jpg)
saveImages may be pushed to registries.
34
registry
image
container
push
commit
![Page 35: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/35.jpg)
dockersavePush an image to a docker registry.
Use tag to point to the appropriate registry.
Remember that no hostname default to DockerHub.
35
# Point to custom registrydocker tag newimage:newtag dockerhub.cr.ridgerun.com:5000/ridgerun/myimage:mytag
# Push imagedocker push dockerhub.cr.ridgerun.com:5000/ridgerun/myimage:mytag
# Point do ridgerun repository at Docker Hubdocker tag myimage:mytag ridgerun/myimage:mytag
# Push imagedocker push ridgerun/myimage:mytag
![Page 36: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/36.jpg)
docker
saveDockerfiles are an alternative way to create an image.
36
# Build an image from a dockerfiledocker build -t imagename:imagetag .
# List imagesdocker images
FROM ubuntu:18.04RUN apt-get update && \ apt-get install -y openssh-server sudo && \ useradd -p $(openssl passwd -1 mgruner) mgruner && \ adduser mgruner sudo
ENTRYPOINT service ssh restart && bash
Dockerfile:
![Page 37: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/37.jpg)
saveDockerfile vs push?
The golden image is a mythical creature.
Nobody knows how the golden image was built.
Avoid the golden image.
37
¯\_(ツ)_/¯THE GOLDEN
IMAGE
![Page 38: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/38.jpg)
docker lifecycle 38
use saveinstall create delete
Improve your image!
![Page 39: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/39.jpg)
docker lifecycle 39
use saveinstall create delete
![Page 40: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/40.jpg)
docker
deleteFinally delete the containers you no longer need.
40
# Stop the container firstdocker stop mycontainer
# Remove the containerdocker rm mycontainer
![Page 41: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/41.jpg)
docker pro tips
41
![Page 42: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/42.jpg)
docker
portainerManage containers through a web server.
Can you figure out the syntax?
42
# Create a persistent memory volumedocker volume create portainer_data
# Run portainer forever!docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
![Page 44: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/44.jpg)
user ifaceHaving the graphical portion of the OS is very useful.
We've found that X2Go is the easiest way.
XFCE is a lightweight desktop environment.
44
docker
# Install x2go clientsudo apt install x2goclient
container
# Install x2go server, desktop environment and sudoapt install x2goserver xfce4 sudo
# Create a useradduser ridgerun
# Give the new user sudo accessadduser ridgerun sudo
# Start ssh serverservice ssh start
![Page 45: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/45.jpg)
user ifaceLaunch X2Go Client.
Configure a session as the following.
Sessions are persistent!
45
![Page 46: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/46.jpg)
so......what is docker useful for?
46
![Page 47: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/47.jpg)
reproducible environments 47
¯\_(ツ)_/¯IT WORKSON MY MACHINE
![Page 48: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/48.jpg)
continuous integration 48
![Page 49: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/49.jpg)
microservices architecture 49
![Page 50: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/50.jpg)
security 50
![Page 51: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/51.jpg)
“In software development perfect is not an adjective, but a verb.”
- Uncle Bob
51
![Page 52: docker - developer.ridgerun.com€¦ · docker is 7 A technology that enables the management and use of containers. A set of tools to architect applications and services. An ecosystem](https://reader035.vdocuments.net/reader035/viewer/2022071117/6003c7d49f048b2814284763/html5/thumbnails/52.jpg)
dockerridgerun 2020
52