Skip to content

Instantly share code, notes, and snippets.

@sunny352
Last active June 29, 2024 12:19
Show Gist options
  • Save sunny352/559b0b5a7a6aeb65197b56e6edaf48be to your computer and use it in GitHub Desktop.
Save sunny352/559b0b5a7a6aeb65197b56e6edaf48be to your computer and use it in GitHub Desktop.
在debian上安装docker及docker-compose
#!/usr/bin/env bash
# export http_proxy=http://##替换成自己的代理地址##
# export https_proxy=http://##替换成自己的代理地址##
# 使用官方源安装docker
apt update
apt install -y \
ca-certificates \
curl \
gnupg \
lsb-release
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update -y
apt install -y docker-ce docker-ce-cli containerd.io
# 迁移docker目录(可选)
systemctl stop docker docker.socket
mv /var/lib/docker /home/docker_lib
ln -s /home/docker_lib /var/lib/docker
systemctl enable docker
systemctl start docker
# 国内镜像都关了,这部分已经不需要了
# # 修改docker镜像源(使用腾讯云镜像源)
# mkdir /etc/docker
# tee /etc/docker/daemon.json <<-'EOF'
# {
# "registry-mirrors": [
# "https://hub-mirror.c.163.com",
# "https://mirror.baidubce.com"
# ]
# }
# EOF
# systemctl daemon-reload
# systemctl stop docker docker.socket
# systemctl start docker
mkdir -p /etc/systemd/system/docker.service.d
# 设置代理
tee /etc/systemd/system/docker.service.d/http-proxy.conf <<-'EOF'
[Service]
Environment="HTTP_PROXY=http://##替换成自己的代理地址##"
Environment="HTTPS_PROXY=http://##替换成自己的代理地址##"
EOF
systemctl daemon-reload
systemctl restart docker docker.socket
# 安装Portainer容器管理工具(可选,需要访问http://localhost:9000进行配置)
docker run --name gui --restart always -d -p 9000:9000 -v "/var/run/docker.sock:/var/run/docker.sock" portainer/portainer-ce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment