DEV Community

Hamid Haghdoost
Hamid Haghdoost

Posted on • Updated on

Install Docker and Docker Compose by single command and use it without sudo :)

I know it looks crazy but to be honest I am frustrated of searching "install docker ubuntu" and copy paste lots of commands every time. If it happens for you a lot, you can bookmark this gist and just copy and paste it to install docker, compose and post installation commands.

for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done  &&
sudo apt-get update &&
sudo apt-get install ca-certificates curl gnupg &&
sudo install -m 0755 -d /etc/apt/keyrings &&
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg &&
sudo chmod a+r /etc/apt/keyrings/docker.gpg &&
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update &&
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin &&
sudo groupadd docker && 
sudo usermod -aG docker $USER && 
newgrp docker && 
sudo docker run hello-world
Enter fullscreen mode Exit fullscreen mode

A shorter way

If you don't want to copy such a long command you can easily run this one:

 /bin/bash -c "$(curl -s https://gist.githubusercontent.com/tuytoosh/b700f17f3ee3ad7f20d533e61de31c56/raw)"
Enter fullscreen mode Exit fullscreen mode

It downloads the gist and runs the commands after getting root password.
I know there are some other standard ways to do this, like maybe using Ansible Playbooks or... but this is the easiest way!

Ciao e buon week-end :)

Top comments (1)

Collapse
 
tuanxt profile image
tuanxt

it is very usefull,
thank you bro