Quick start to install Docker and Docker-compose on Linux


# (optional) remove old
sudo yum remove -y docker \
                  docker-ce-cli \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
# Docker              
sudo yum install -y yum-utils \
  device-mapper-persistent-data \
sudo yum-config-manager \
    --add-repo \
sudo yum install -y docker-ce

sudo systemctl start docker
sudo systemctl enable docker  # start docker at boot up

# (optional) Verify
sudo docker run hello-world

# When fail to start docker:
firewall-cmd --get-active-zones
firewall-cmd --zone=docker --change-interface=docker0
firewall-cmd --runtime-to-permanent
systemctl restart docker


Install docker-compose

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

# (optional) Verify
docker-compose --version


# Move fat docker to other folder with symlink - Linux (bash)
sudo systemctl stop docker
sudo mv /var/lib/docker /data/.
sudo ln -s /data/docker /var/lib/docker
sudo systemctl start docker

# Move fat docker to other folder with symlink - Windows (Powershell)
move C:\ProgramData\docker\* D:\ProgramData\docker
cmd /c mklink /d C:\ProgramData\docker D:\ProgramData\docker

# Add default Log rotation
sudo bash -c 'cat >> /etc/docker/daemon.json' << EOF
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "512"
sudo systemctl daemon-reload
sudo systemctl restart docker

# Execute docker without sudo
sudo groupadd docker
sudo usermod -aG docker $USER
#> Re-login to apply

# Show other docker version
yum list docker-ce --showduplicates | sort -r

# Restart 
## daemon
sudo systemctl daemon-reload
## docker service
sudo systemctl restart docker.service
## docker
sudo systemctl restart docker

# Remove stuff
docker container prune    # Remove all stopped containers
docker volume prune     # Remove all unused volumes
docker image prune     # Remove unused images
docker system prune     # All of the above, in this order: containers, volumes, images
docker ps -a -q | % { docker rm $_ }     # Remove container with PowerShell
docker rm $(docker ps -a -q)     # Remove container with Bash
docker volume rm $(docker volume ls -f dangling=true -q)


# (optional) Remove old
sudo apt-get remove -y docker-ce docker-ce-cli docker docker-engine docker.io containerd runc

# Setting up
sudo apt-get update
sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \

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

## (optional) Verify fingerprint 
sudo apt-key fingerprint 0EBFCD88

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

# Install latest
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io

## (optional) Install other version.  PS."18.09 no need to install docker-ce-cli"
apt-cache madison docker-ce
sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

# (optional) Verify
sudo docker run hello-world