Skip to content

Instantly share code, notes, and snippets.

@bmmalone
Last active March 16, 2022 09:59
Show Gist options
  • Save bmmalone/2b4e843ce99bad74311837ddd7546b7b to your computer and use it in GitHub Desktop.
Save bmmalone/2b4e843ce99bad74311837ddd7546b7b to your computer and use it in GitHub Desktop.
Install docker on Debian. Further, create the docker group and add the current user to it. Finally, set a custom location for storing images.
#! /usr/bin/env bash
image_loc="/data/docker"
###
# https://docs.docker.com/engine/install/debian/
###
# set up the docker repository
sudo apt update
sudo apt -y install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# install docker
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
# test installation
sudo docker run hello-world
###
# https://docs.docker.com/engine/install/linux-postinstall/
###
# create the docker group if it does not already exist
# it is fine if the group already exists
sudo groupadd docker || true
# add users
sudo usermod -aG docker $USER
# update groups
newgrp docker
###
# It is necessary to restart the service for the new permissions
# and such to work.
#
# See: https://github.com/jgsqware/clairctl/issues/60#issuecomment-402564931
###
sudo service docker restart
###
# Change the location of docker images
#
# https://www.ibm.com/docs/ja/cloud-private/3.1.0?topic=pyci-specifying-default-docker-storage-directory-by-using-bind-mount
###
docker rm -f $(docker ps -aq)
docker rmi -f $(docker images -q)
sudo service docker stop
sudo rm -rf /var/lib/docker
sudo mkdir /var/lib/docker
sudo mkdir $image_loc
sudo chown $USER: $image_loc
sudo mount --rbind $image_loc /var/lib/docker
#sudo systemctl start docker
sudo service docker start
###
# For the binding to come back after rebooting, it is necessary to update /etc/fstab.
###
@bmmalone
Copy link
Author

In practice, it seems that using symlinks are an easier option compared to using bind mounts for using different locations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment