Skip to content

Instantly share code, notes, and snippets.

@erkobridee
Created November 27, 2024 15:20
Show Gist options
  • Save erkobridee/ec130b16edd9047bd8f309a9b22b5777 to your computer and use it in GitHub Desktop.
Save erkobridee/ec130b16edd9047bd8f309a9b22b5777 to your computer and use it in GitHub Desktop.

Docker on Ubuntu

Step 01 - Install Docker

# If more information needed, head to this tutorial:
# https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-22-04

# Firstly update your existing list of packages
sudo apt update

# Now install the prerequesites packages with apt and HTTPS
sudo apt install apt-transport-https ca-certificates curl software-properties-common

# Add the GPG key of the official Docker repository to your system
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# Add the Docker repository to apt sources
echo "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

# Update your existing packages again
sudo apt update

# Make sure you install Docker from the Docker repository AND NOT from the Ubuntu reposiroty
# You should see a candidate version as "version_of_docker~ubuntu-jammy"
apt-cache policy docker-ce

# Now install docker
sudo apt-get install docker.io

# Ensure docker is starting
sudo systemctl status docker

# If Docker is not started, enable docker.socket
sudo systemctl enable docker.socket
sudo systemctl start docker.socket
sudo systemctl restart docker
sudo systemctl status docker

Step 02 - Configure Docker

# Add your user to docker groups
sudo usermod -aG docker ${USER}
# alternative way to get the username
sudo usermod -aG docker $(whoami)

# Apply the new group membership
su - ${USER}
# alternative way to get the username
su - $(whoami)

Step 03 - Install Docker Compose

# Install docker-compose
sudo curl -SL https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-linux-x86_64 -o /usr/bin/docker-compose
sudo chmod a+x /usr/bin/docker-compose

Step 04 - Setup the Internet access for the Docker Containers

sudo cat > /etc/docker/daemon.json << EOF
{
    "dns": ["10.0.0.2", "8.8.8.8"]
}
EOF
sudo systemctl restart docker
sudo systemctl enable docker
sudo chmod a+rwx /var/run/docker.{pid,sock}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment