当前位置: 首页 > article >正文

Ubuntu安装Docker和Docker Compose

1. 安装前准备: 

#安装前先卸载操作系统默认安装的docker,
sudo apt-get remove docker docker-engine docker.io containerd runc

#安装必要支持
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release


# 阿里源(推荐使用阿里的gpg KEY)
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg


#添加 apt 源:
#Docker官方源
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


#阿里apt源
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null


#更新源
sudo apt update
sudo apt-get update

2. 安装Docker:

#安装最新版本的Docker
sudo apt install docker-ce docker-ce-cli containerd.io
#等待安装完成

#查看Docker版本
sudo docker -v

#查看Docker运行状态
sudo systemctl status docker

3. 安装Docker Compose插件 :

# 安装Docker Compose
sudo apt install docker-compose

 Docker Compose

  • 是Docker生态系统中的一个工具,主要用于简化多个Docker容器的应用部署和服务编排。
  • 通过一个名为docker-compose.yml的YAML配置文件来定义一个多容器的应用栈,包含了多个服务、网络以及卷等资源的配置。
  • 使用Docker Compose,用户可以通过一条命令(如docker-compose up)来启动、停止和重启整个应用栈中包含的所有服务,并且这些服务之间可以根据配置进行通信和资源共享。
报错1:Package *** has no installation candidate

原因是修改了apt的镜像源后没有更新软件包:只执行了 apt update 没有执行 apt-get upgrade,apt源里没有docker,需要添阿里源

测试拉取镜像运行:

docker pull hello-world

docker run hello-world
报错2:拉取镜像报错,Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

解决:配置加速地址并重启docker

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://docker.m.daocloud.io"
]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

测试拉取hello-world和运行没问题了说明已经装好了。 

设置非root用户使用docker命令:
#创建docker组

sudo groupadd docker

#添加ithing进入docker组

sudo gpasswd -a ithing docker

#重启docker服务

sudo systemctl restart docker

#接下来就可以使用你添加的用户(ithing)进行使用docker命令了

exit 退出虚拟机重连生效

 参考:

  • 官方文档 Ubuntu | Docker Docs
  • Ubuntu 22.04下Docker安装(最全指引)_docker ubuntu2204-CSDN博客

http://www.kler.cn/news/328658.html

相关文章:

  • 高性价比PCB分板机高速主轴SycoTec 4025 HY
  • LeetCode 面试经典150题 172.阶乘后的零
  • PCL 最远点采样(FPS)
  • 微服务SpringSession解析部署使用全流程
  • 10.数据结构与算法-线性表的应用(线性表与有序表的合并)
  • 【K8S系列】深入解析 Kubernetes 网络策略(二)
  • Redis篇(Java操作Redis)
  • 微服务JSR303解析部署使用全流程
  • tailwindcss group-hover 不生效
  • Spring Boot驱动的足球青训俱乐部管理解决方案
  • 鹏哥C语言62---第9次作业:函数递归练习
  • 2025 年 IT 前景:机遇与挑战并存,人工智能和云计算成重点
  • 【Android 源码分析】Activity生命周期之onPause
  • local minima 的问题如何解决
  • .Net 基于IIS部署blazor webassembly或WebApi
  • 用Python+flask+mysql等开发的Excel数据资产落地工具
  • 【一文读懂】C#如何实现通用的排序功能
  • 车辆重识别(利用扩散模型合成有效数据进行行人再识别预训练)论文阅读2024/9/27
  • 【树莓派系列】树莓派首次开机配置
  • LeetCode 面试经典150题 50.Pow(x,n)
  • VMware 设置静态IP
  • 鸿蒙开发(NEXT/API 12)【硬件(取消注册智慧出行连接状态的监听)】车载系统
  • 记录Mybatis分页查询排序问题: Encountered unexpected token: “and“ “AND“
  • C++:STL(四)之vector的基本介绍与使用方式|容器接口
  • Python NumPy 数据分析:处理复杂数据的高效方法
  • 数据结构-3.9.栈在递归中的应用
  • React、Vue.js和Angular三大主流框架的选择对比
  • yum使用阿里云的镜像源报错 Failed connect to mirrors.aliyuncs.com:80; Connection refused“
  • 智能工厂非标自动化集成商
  • 【Python】数据可视化之点线图