Legacy post. This article was written between 2016 and 2018. Software versions, commands and services mentioned here may be outdated. Check the official documentation before running anything.

The goal of this tutorial is to install the Docker engine and share some useful command lines to work with it.

What’s Docker?

All you need to know about Docker is here

Installation

Everything is here

Install Portainer.io

Manage Docker with a GUI

docker run -d -p 9000:9000 --name portainer -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer

See more about portainer.io

Install Docker Compose

Compose is a tool for defining and running multi-container Docker applications… See more here

curl -L "https://github.com/docker/compose/releases/download/1.10.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version

See more here

Useful docker command line

  • Get the list of running containers
    sudo docker ps -a 
    
  • Kill a container
    sudo docker kill YOUT_CONTAINER_ID
    
  • Remove a container
    docker rm CONTAINER_ID
    
  • Get the list of images
    sudo docker images
    
  • Remove an image
    docker rmi IMAGE_ID
    
  • Interact with the container
    docker exec -i -t CONTAINER_ID /bin/bash
    
  • Restart the Docker service
sudo systemctl restart docker
  • Avoid using sudo
groupadd docker
usermod -aG docker YOUR_USER
  • Bind your Docker repository to an external file system
sudo service docker stop
mv /var/lib/docker /docker
sudo ln -s /docker /var/lib/docker
sudo service docker start
  • Set DOCKER_OPTS
sudo vim /etc/default/docker >> DOCKER_OPTS="-g $(readlink -f /var/lib/docker)"

DOCKER_OPTS is deprecated in recent Docker versions; use /etc/docker/daemon.json instead.

Install on Raspberry

curl -sSL https://get.docker.com | sh

See more here

systemctl stop docker

mv /var/lib/docker /home//docker

ln -s /home//docker /var/lib/docker

systemctl start docker