Skip to content

Instantly share code, notes, and snippets.

@imtiazShakil
Last active June 30, 2024 11:22
Show Gist options
  • Save imtiazShakil/bb55c4841e6aa08e53e0103bb59fda2b to your computer and use it in GitHub Desktop.
Save imtiazShakil/bb55c4841e6aa08e53e0103bb59fda2b to your computer and use it in GitHub Desktop.
Docker installation help
  • Didn't install docker desktop for linux (i think it's heavy, as it has its own vm)
  • installed docker engine for linux
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
# If you use an Ubuntu derivative distro, such as Linux Mint, you may need to use UBUNTU_CODENAME instead of VERSION_CODENAME.
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /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 docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Manage Docker as a non-root user

# Create the docker group.
sudo groupadd docker

# Add your user to the docker group.
sudo usermod -aG docker $USER

# run the following command to activate the changes to groups:
newgrp docker

# Verify that you can run docker commands without sudo
docker run hello-world

Configure default logging driver

sudo nano /etc/docker/daemon.json

### daemon.json
{
  "log-driver": "local"
}
###

sudo service docker restart 

(Optional) Change Docker Storage base (container + image)

sudo nano /etc/docker/daemon.json

### daemon.json
{
  "log-driver": "local",
  "data-root": "/new/path/to/docker-data"
}
###

sudo service docker stop

# Copy the files to the new location
sudo rsync -axPS /var/lib/docker/ /new/path/to/docker-data
# -a, --archive             archive mode; equals -rlptgoD (no -H,-A,-X)
# -x, --one-file-system     don't cross filesystem boundaries
# -P                        show progress during transfer
# -S, --sparse              handle sparse files efficiently

sudo service docker start

# Check Docker has started up using the new location
docker info | grep 'Docker Root Dir'

# remove docker old storage directory
sudo rm -rf /var/lib/docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment