Docker
De TechShareRoom wiki
Instalación
#!/bin/bash
docker --version
dpkg --configure -a
# Remove possible old packages
apt remove -y docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc
# Add Docker's official GPG key
apt -y update
apt -y install ca-certificates curl gnupg
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
# Add the repository to Apt sources:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt -y update
# Install docker
apt -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-compose
docker --version
Actualizar contenedor
Antes de realizar esta operación por primera vez haz un backup del contenedor. Si no has tenido en cuenta los datos externos vas a perderlos todos al volver a levantar el mismo contenedor actualizado.
#!/bin/bash
# Example with portainer
cd /home/usuario/portainer
docker stop portainer
docker rm portainer
docker pull portainer/portainer-ce
docker-compose up -d
Backup contenedor
service docker stop
cd /var/lib
sudo tar -czvf docker.tar.gz docker
service docker start
Restore contenedor
# Install docker
service docker stop
cp /var/lib /var/lib/docker_default
rm -rf /var/lib/docker
tar -xzvf docker.tar.gz -C /var/lib
service docker start