Docker Tutorial

From RidgeRun Developer Wiki

Presentation

<pdf page="0" height="455">File:Rr training sesssions docker.pdf</pdf>

Commands Quick Reference

Install

On Debian-based systems Docker may be installed via Apt (taken from the official documentation):

# Uninstall old versions
sudo apt remove docker docker-engine docker.io containerd runc

# Install dependencies
sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

# Install GPG Key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# Add Docker PPA
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

# Finally install
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

To run as non-root user:

# Create the docker group
sudo groupadd docker

# Add yourself to the group
sudo usermod -aG docker $USER

# To avoid re-logging
newgrp docker

# Test proper installation
docker ps

Other supported OS:

Create Containers

These are my go-to recipes for daily container creation:

# Basic container creation
docker create -ti --name mycontainer ubuntu:18.04

# 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 volume for future use
docker create -ti -v myvolume:/host ubuntu:18.04

# Additional useful options
# -m Memory limit
# -c CPU percentage
# --restart Restart policy
# --rm Remove container after usage
# -e Environment variable
docker create -ti -m 1G -c 1.5 --restart unless-stopped --rm -e MYENV=myenv ubuntu:18.04