在腾讯云上的Ubuntu系统中安装Docker环境可以按照以下步骤操作,适用于大多数Ubuntu版本(如18.04/20.04/22.04等):
步骤1:更新系统软件包
sudo apt update && sudo apt upgrade -y
步骤2:安装依赖工具
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
步骤3:添加Docker官方GPG密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
步骤4:添加Docker软件源
根据你的Ubuntu版本选择对应的源(以下以jammy为例,对应22.04):
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
如果系统版本不同,请将
$(lsb_release -cs)替换为对应的代号(如20.04是focal,18.04是bionic)。
步骤5:安装Docker引擎
sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io
步骤6:验证安装
sudo docker run hello-world
如果看到欢迎信息,说明安装成功。
可选配置
-
将当前用户加入docker组(避免每次使用
sudo):sudo usermod -aG docker $USER newgrp docker # 刷新组权限(或重新登录) -
设置Docker开机自启:
sudo systemctl enable docker -
配置腾讯云镜像提速(国内服务器推荐):
- 登录腾讯云容器服务控制台,获取专属提速器地址。
- 编辑配置文件:
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://你的提速器地址.mirror.aliyuncs.com"] } EOF - 重启Docker生效:
sudo systemctl restart docker
常见问题
- 权限问题:如果遇到
Permission denied,确保用户已加入docker组并重新登录。 - 版本兼容性:较旧的Ubuntu版本可能需要使用其他源(如
ubuntu-$(lsb_release -cs)改为ubuntu-bionic)。
通过以上步骤,你可以在腾讯云Ubuntu服务器上快速搭建Docker环境。
云服务器