Install and Configure Docker

Install Docker

Source

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 https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu 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

Others…

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

Install docker-compose

Source

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

Configure Docker

Source

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: admin

Leave a Reply

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