Install docker and compose with one command

Docker is fun. For a person like me who is not comfortable with the Command Line Interface, installing it is not. There are four or five steps one needs to perform to get docker and docker compose working.

Step 1

Install docker: sudo apt install docker.io . To check if docker is installed properly run docker --version , if you see something like this below then it means docker is installed properly.

Docker version 19.03.Docker version 19.03.8, build afacb8b7f08, build afacb8b7f0

But if you try any other docker command, like docker ps then you'll encounter an error.

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/json: dial unix /var/run/docker.sock: connect: permission denied

To overcome this either use sudo every time before the docker command e.g. sudo docker ps or go to Step 3.

Step 2

Install docker compose: sudo apt install docker-compose

Step 3

To not use sudo always you'll have to add your user to the group docker. Just copy the following command in your terminal and press enter. That'll do the job.

sudo usermod -aG docker $USER

Don't forget to logout and log in to enable the changes.

Step 4

Docker and Compose are working now. Sooner or later you'll observe that it doesn't start on its own whenever the system reboots. To make that happen docker service needs to be enabled.

sudo systemctl enable docker

And bravo! docker is up and running. Wait! did I say running? No no no no, it's still not running; check this by using

sudo systemctl status docker

You should see something like

● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vend>
     Active: inactive (dead)
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com

Step 5

Start docker by using sudo systemctl start docker and FINALLY! you're done.


Hey! you said install docker in one command.

Oh! I completely forgot. Though there is no one single command as such; all the command above can be clubbed together and run in one go. Take a look below.

sudo apt install -y docker.io && sudo apt install -y docker-compose && sudo systemctl enable docker && sudo usermod -aG docker $USER && sudo systemctl start docker

Copy and paste this command in your terminal and press Enter that's it.

Note: Do not forget to log out and log back in again to see the changes take effect.

See you some other time. Till then buh-bye.