Install and Configure Docker

Install Docker


Run these commands on your ubuntu system to install Docker.

sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] focal stable"
sudo apt update
sudo apt install docker-ce

Check the instalation using this command…

sudo systemctl status docker

Getting docker to run without the root user, add your username to the docker group…

sudo usermod -aG docker ${USER}

To apply the new group membership, log out of the server and back in.

Test Docker

docker run hello-world

Basic Commands

See all images

docker images

See all containers

docker containers

Running containers

docker ps


docker info
docker images
docker pull
docker run
docker start
docker stop
docker stats
docker system df
docker system prune

Install docker-compose


sudo curl -L " -s)-(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version # Test

Configure Docker


We have to change the data directory from / to somewhere with more space – it will easily run into GBs.

Stop docker using command…

sudo systemctl stop docker

Edit /etc/docker/daemon.json (if it doesn’t exist, create it) and include:

  "data-root": "/new/path/to/docker-data"

Copy existing docker data to the new location…

sudo rsync -axPS /var/lib/docker/ /new/path/to/docker-data

Restart Docker and check…

sudo systemctl start docker
docker info | grep 'Docker Root Dir'
docker ps
Author: Binny V A
A philosopher programmer who specializes in backend development and stoicism.

Leave a Reply

Your email address will not be published. Required fields are marked *