Docker
什么是Docker
Docker是linux容器的一种封装,提供简单易用的容器使用接口,在容器中打包和运行应用的功能。
Docker的隔离和安全性可以在主机上同时运行多个容器,不用担心环境问题。
Docker三个重要概念
Docker image:容器(container)依赖于image运行,镜像是只读的,一个镜像可以运行多个容器,镜像包含了每个容器私有的系统文件,使其与主机和其他容器隔离。
镜像可以通过Dockerfile创建,也可以从Docker hub/registry上下载。
Docker container:容器运行在linux本地,并且与其他容器共享主机内核,容器是一个隔离环境,多个容器之间不会相互影响,保证容器中的程序运行在一个相对安全的环境中。
Get Docker
install Docker
yum install docker -y
复制
启动Docker服务
systemctl start docker.service
systemctl enable docker.service复制
验证Docker是否安装成功
docker version
复制
命令行返回版本相关信息,表示安装成功。
修改Docker配置文件 daemon.json
配置使用Docker加速器(连接 Docker 的官方仓库很慢)
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"live-restore": true
}复制
为Docker指定DNS服务器
vim /etc/docker/daemon.json
# 如果存在文件,则只添加该dns行
{
"dns": ["8.8.8.8", "8.8.4.4"]
}复制
Hello World
在Docker上运行hello world镜像
将image从仓库拉取到本地
docker pull hello-world
复制查看images
docker images
# 结果如下
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hello-world latest fce289e99eb9 10 months ago 1.84 kB复制运行hello world image文件
docker run hello-world
# 显示如下,表示成功
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.复制输出这段提示之后,hello world容器自动停止。
Docker命令
Docker命令大全(https://www.runoob.com/docker/docker-command-manual.html)
参考资料
Get Docker Engine - Community for CentOS(https://docs.docker.com/install/linux/docker-ce/centos/)
Orientation and setup(https://docs.docker.com/get-started/)
文章转载自技术白小白,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
NineData 社区版征文评测活动圆满收官!
NineData
156次阅读
2025-04-09 11:01:15
轻松上手:使用 Docker Compose 部署 TiDB 的简易指南
shunwahⓂ️
83次阅读
2025-04-27 16:19:49
Dify使用deepseek
golang算法架构leetcode技术php
51次阅读
2025-04-21 10:35:08
Pigsty v3.4 发布:更好的备份与 PITR,排序,基础设施与应用
IvorySQL开源数据库社区
47次阅读
2025-04-11 15:34:47
GreatSQL社区月报 | 2025.3
GreatSQL社区
30次阅读
2025-04-15 09:49:59
Harbor使用指南
老柴杂货铺
26次阅读
2025-04-12 00:03:42
KubeKey部署Kubernetes
老柴杂货铺
19次阅读
2025-04-11 02:16:37
Docker镜像:从入门到精通的实战指南
韩公子的Linux大集市
12次阅读
2025-04-09 20:59:12
Qwen3震撼发布,用openGauss x Dify抢先体验,秒速搭建智能知识库
Gauss松鼠会
11次阅读
2025-05-07 10:05:56
Qwen3震撼发布,用openGauss x Dify抢先体验,秒速搭建智能知识库
openGauss
11次阅读
2025-05-06 10:19:35