Docker | 入门:安装与配置

Docker | 入门:安装与配置

Docker 和传统虚拟机区别

对于传统虚拟机:

虚拟出一套硬件,运行一个完整的操作系统,并在这个操作系统上安装和运行软件。

对于 Docker: 将一个个容器隔离开。

容器内的应用直接运行在宿主机的内容,容器没有自己的内核。每个容器内都有一个属于自己的文件系统,互不影响。

Docker 的基本组成

镜像(Image):类似于一个模板,通过它来创建容器服务。可以创建多个容器,并且最终服务运行或者项目运行就是在容器中。

容器(container):容器通过镜像来创建。Docker 通过容器技术,独立运行一个或一组应用。

仓库(repository):存放镜像的地方。

Docker 安装

Linux 系统安装

官方文档

卸载旧版本

shell 复制代码
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

Add Docker's official GPG key:

shell 复制代码
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

Add the repository to Apt sources:

shell 复制代码
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

安装最新版 Docker 软件包

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

测试

查看 Docker 是否安装成功

shell 复制代码
docker --version

测试 hello-world

shell 复制代码
sudo docker run hello-world

从上图可以看出。Docker run 做的事情:先寻找 hello-world 镜像,如果没找到,就去远程拉取。拉取成功后就运行,输出 Hello from Docker.

查看镜像

shell 复制代码
docker images

会发现存在 hello-world 镜像。

配置阿里云镜像加速

shell 复制代码
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF' 
{ 
	"registry-mirrors":["https://ur5v53mu.mirror.aliyuncs.com"] 
} 
EOF 
sudo systemctl daemon-reload 
sudo systemctl restart docker
相关推荐
赵民勇10 小时前
fuse-overlayfs命令详解
linux·容器
JAVA社区13 小时前
Java高级全套教程(十一)—— Kubernetes 超详细企业级实战详解
java·运维·微服务·容器·面试·kubernetes
陈陈CHENCHEN16 小时前
【Kubernetes】Kubeadm 搭建生产级 K8s 高可用集群
云原生·容器·kubernetes
杰克逊的日记17 小时前
K8s+GPU+大模型运维主要技术点
运维·容器·kubernetes
一个向上的运维者19 小时前
Docker 自定义网络中容器无法通过宿主机 IP 访问服务的完整排障记录
网络·tcp/ip·docker
ClouGence19 小时前
CloudDM 3.1.0 发布:初始化、驱动管理与升级体验全面优化
docker·开源·数据库管理·企业开发·数据库工具·数据库运维
PascalMing20 小时前
K8s集群安装部署完整指南(Ubuntu24.04+K8s1.28)
云原生·容器·kubernetes
IT策士20 小时前
第 34 篇 k8s之存储基础:emptyDir 与 hostPath
云原生·容器·kubernetes
zandy101120 小时前
Hermes Agent 安装与配置全流程(2026年6月最新版)
docker·agent·安装教程·kimi