ubuntu20.04安装docker及运行

ubuntu20.04安装docker及运行

ubuntu环境版本

Ubuntu Focal 20.04 (LTS)

查看系统版本

c 复制代码
root@ubuntu20043:~# cat /proc/version
Linux version 5.15.0-78-generic (buildd@lcy02-amd64-008) (gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #85-Ubuntu SMP Fri Jul 7 15:25:09 UTC 2023

使用存储库安装docker

卸载可能存在或未安装成功的docker(新系统无需操作)

c 复制代码
sudo apt-get remove docker docker-engine docker-ce docker.io

设置存储库

root用户命令前不用加sudo,我习惯性的加上了

1、更新apt-get

c 复制代码
sudo apt-get update

2、安装软件包允许apt-get通过 HTTPS 使用存储库

c 复制代码
sudo apt-get install ca-certificates curl gnupg lsb-release

3、添加GPG密钥并设置存储库,可以使用官方的也可以使用阿里云镜像源的,任选其一

c 复制代码
sudo mkdir -p /etc/apt/keyrings

3.1、docker官方GPG秘钥

c 复制代码
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

设置存储库

c 复制代码
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
c 复制代码
root@ubuntu20043:~# sudo mkdir -p /etc/apt/keyrings
root@ubuntu20043:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
root@ubuntu20043:~# echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

如果docker官方的太慢可以切换到阿里云镜像源的

3.2、阿里云镜像源的GPG秘钥

c 复制代码
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

设置存储库

c 复制代码
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

4、安装docker

4.1、更新apt-get

c 复制代码
sudo apt-get update

4.2、安装,可能会花费点时间请耐心等待

c 复制代码
apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

5、安装完成后查询docker版本

c 复制代码
docker version

6.查看docker状态

c 复制代码
 systemctl status docker

6.1、如果没有启动可运行以下命令启动

c 复制代码
systemctl start docker

6.2设置开机自启动

c 复制代码
sudo systemctl enable docker

7、验证docker是否正常运行,可以使用一个"hello-world"样例程序

c 复制代码
docker run hello-world
相关推荐
荣--2 小时前
一键部署不是为了省时间 —— 它是把"买来的 PaaS"变成"自己的平台"的拐点
运维·zabbix·工程化·一键部署·平台化·边界设计
江华森3 小时前
动手实战学 Docker — 从零到集群编排完全指南
运维
宋均浩3 小时前
# Docker 镜像瘦身实战:从 1.2G 到 80MB 的五个优化步骤
ci/cd·docker
Avan_菜菜19 小时前
FRP 内网穿透完整实战:从 HTTP 映射到 HTTPS 自签代理
运维·nginx·https
程序员老赵20 小时前
10 分钟部署 OpenCode:Docker 一键安装,浏览器打开就能用 AI 写代码(附完整命令与排错)
docker·容器·ai编程
WangMingHua1111 天前
LM Studio Docker 部署——本地大模型一键启动
docker
SelectDB2 天前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台
运维·后端·自动化运维
曲幽2 天前
别再用网页翻译看源码了!你的私人翻译神器LibreTranslate,部署避坑指南来了
python·docker·web·pot·translate·libretranslate·arogstranslate
XIAOHEZIcode3 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
用户0328472220704 天前
如何搭建本地yum源(上)
运维