Millefeuille revised this gist . Go to revision
1 file changed, 3 insertions
upgrade_docker.sh
| @@ -8,6 +8,9 @@ fi | |||
| 8 | 8 | ## Update lists | |
| 9 | 9 | apt update | |
| 10 | 10 | ||
| 11 | + | ## Install required packages | |
| 12 | + | apt install curl apt-transport-https gnupg software-properties-common | |
| 13 | + | ||
| 11 | 14 | ## Remove potential old installation of docker | |
| 12 | 15 | for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do apt-get remove $pkg; done | |
| 13 | 16 | ||
Millefeuille revised this gist . Go to revision
1 file changed, 5 insertions
gistfile1.txt renamed to upgrade_docker.sh
| @@ -1,8 +1,13 @@ | |||
| 1 | + | #!/bin/sh | |
| 2 | + | ||
| 1 | 3 | if [ "$(id -u)" -ne 0 ]; then | |
| 2 | 4 | echo "This script must be run as root" | |
| 3 | 5 | exit 1 | |
| 4 | 6 | fi | |
| 5 | 7 | ||
| 8 | + | ## Update lists | |
| 9 | + | apt update | |
| 10 | + | ||
| 6 | 11 | ## Remove potential old installation of docker | |
| 7 | 12 | for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do apt-get remove $pkg; done | |
| 8 | 13 | ||
Millefeuille revised this gist . Go to revision
1 file changed, 35 insertions
gistfile1.txt(file created)
| @@ -0,0 +1,35 @@ | |||
| 1 | + | if [ "$(id -u)" -ne 0 ]; then | |
| 2 | + | echo "This script must be run as root" | |
| 3 | + | exit 1 | |
| 4 | + | fi | |
| 5 | + | ||
| 6 | + | ## Remove potential old installation of docker | |
| 7 | + | for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do apt-get remove $pkg; done | |
| 8 | + | ||
| 9 | + | ## Add Docker's official GPG key: | |
| 10 | + | apt-get install -y ca-certificates | |
| 11 | + | install -m 0755 -d /etc/apt/keyrings | |
| 12 | + | curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc | |
| 13 | + | chmod a+r /etc/apt/keyrings/docker.asc | |
| 14 | + | ||
| 15 | + | ## Add the repository to Apt sources: | |
| 16 | + | echo \ | |
| 17 | + | "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ | |
| 18 | + | $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ | |
| 19 | + | tee /etc/apt/sources.list.d/docker.list > /dev/null | |
| 20 | + | apt-get update | |
| 21 | + | ||
| 22 | + | ## Install docker | |
| 23 | + | apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | |
| 24 | + | docker run --rm hello-world | |
| 25 | + | ||
| 26 | + | ## Create docker group if not present | |
| 27 | + | if ! getent group docker > /dev/null; then | |
| 28 | + | groupadd docker | |
| 29 | + | fi | |
| 30 | + | ||
| 31 | + | ## Add argument user to docker group | |
| 32 | + | if [ -n "$1" ]; then | |
| 33 | + | usermod -aG docker $1 | |
| 34 | + | sudo -i -u $1 docker run --rm hello-world | |
| 35 | + | fi | |