One command to install Docker and Docker compose on Ubuntu

Matt Wang
2 min readDec 11, 2021
Installation by one command

The Command

Copy & paste the following command then enjoy your teatime during the installation process:

/bin/bash -c "$(curl -fsSL https://git.io/JDGfm)"

Once the script runs successfully, you need to refresh the current user state by executing the command below:

sudo su -l $USER. Or see other workarounds here [3].

Now the docker environment has been set up completely.

Want to know more, see the content below.

OS requirements

  • Ubuntu Impish 21.10
  • Ubuntu Hirsute 21.04
  • Ubuntu Focal 20.04 (LTS) ( Tested on it)
  • Ubuntu Bionic 18.04 (LTS)

Description

After installing Docker on Ubuntu several times, a shell script was created to make this process easier.

As laziness is one of the three great virtues of a programmer[1], you may prefer to copy & paste the following command line to get Docker ready on your Ubuntu.

/bin/bash -c “$(curl -fsSL https://git.io/JDGfm)"

However, if you wanna dig into the script, you can have a look at the following code (it is basically from Docker official guide [2]), and I just make it simpler to use.

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release
sudo rm -rf /usr/share/keyrings/docker-archive-keyring.gpgcurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpgecho \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get updatesudo apt-get install -y docker-ce docker-ce-cli containerd.iosudo usermod -a -G docker $USERsudo curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-linux-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

References:

[1] https://avdi.codes/the-three-virtues/

[2] https://docs.docker.com/engine/install/ubuntu/

[3] https://askubuntu.com/questions/250720/is-it-necessary-to-reboot-after-changing-group-membership

--

--

Matt Wang

Empowering others through handy and innovative tech solutions and sharing knowledge. Stay tuned with my new articles.