新手快速入门Docker,轻松掌握Docker安装与使用
off999 2025-01-13 16:49 29 浏览 0 评论
安装
使用官方安装脚本自动安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun手动安装
CentOS 7 (使用yum进行安装)
卸载旧版docker
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils
# Step 2: 添加软件源信息 (推荐使用下面阿里云源)
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 添加阿里云源信息
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 开启一些选项 (这一步可跳过)
sudo yum-config-manager --enable docker-ce-nightly
sudo yum-config-manager --enable docker-ce-test
# 关闭选项
sudo yum-config-manager --disable docker-ce-nightly
# 安装 Docker-CE
sudo yum install docker-ce docker-ce-cli containerd.io验证
sudo docker version启动docker
sudo systemctl start docker读者福利:关注小编+转发文章+私信【项目】获取整理好的100+个Java项目视频+源码+笔记
配置镜像加速器
可以上阿里云获取个人加速地址
https://dev.aliyun.com/
https://cr.console.aliyun.com/cn-shenzhen/instances/mirrors
修改daemon配置文件/etc/docker/daemon.json使用加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://e3b4lt8s.mirror.aliyuncs.com"]
}
EOF重启
sudo systemctl daemon-reload
sudo systemctl restart dockerhello world
docker run hello-world命令
查看帮助
docker --helpUsage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/root/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST
env var and default context set with "docker context use")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
builder Manage builds
config Manage Docker configs
container Manage containers
context Manage contexts
engine Manage the docker engine
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.查看指定命令帮助
docker images --helpUsage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Options:
-a, --all Show all images (default hides intermediate images)
--digests Show digests
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print images using a Go template
--no-trunc Don't truncate output
-q, --quiet Only show numeric IDs常用命令
查看本地镜像
docker images
docker images -a # 查看本地所有镜像(包括悬空镜像)
docker images -q # 查看本地镜像的镜像ID信息
docker images -qa
docker images --digests # 显示镜像的摘要写信息
docker images --no-trunc # 查看完整的镜像信息搜索镜像
docker search nginx搜索点赞数>30的镜像
docker search -s 30 nginx
docker search --filter=stars=20 nginx列出自动构建的镜像
docker search --automated nginx
docker search --filter=is-automated=true nginx拉取镜像
docker pull nginx == docker pull nginx:latest
docker pull nginx:3.2删除镜像
docker rmi hello-world强制删除镜像
docker rmi -f hello-world删除多个镜像
docker rmi -f hello-world nginx删除全部镜像
docker rmi -f $(docker images -qa)
1容器命令
容器不但可以包含软件, 容器也可以包含一个操作系统
docker search centos新建并运行容器
docker run查看帮助
docker run --help
# Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]运行容器
docker run -it centos
docker run -it centos /bin/bash-i: 以交互模式启动容器, 和-t搭配使用
-t: 为容器重新分配一个输入终端
docker run -it 0d120b6ccaa8指定容器新名字
docker run -it --name mycentos centos查看正在运行的容器
docker ps查看正在运行+历史运行过的容器
docker ps -a查看上一次运行的容器
docker ps -l
docker ps -lq查看最近2次运行的容器
docker ps -n 2关闭并退出容器
exit只退出不关闭容器
ctrl+p+q 重启启动容器
docker start ID
docker start 04ac5ae5d5fb停止容器
docker stop ID
docker stop 04ac5ae5d5fb强制停止容器
docker kill ID删除已停止的容器
docker rm ID强制删除容器
docker rm -f ID一次性所有容器
docker rm -f $(docker ps -qa)
1以守护进程启动容器
docker run -d centos # [这样会马上退出]不退出
docker run -d centos /bin/sh -c "while true; do echo hello soul; sleep 2; done"查看容器日志
docker logs ID
docker logs -f -t --tail 100 ID查看容器内运行的进程
docker top ID
docker top e7574dd446d6查看容器内部细节
docker inspect ID进入正在运行的容器
docker attach ID
docker exec -t ID /bin/bash直接容器执行命令
docker exec -t ID ls -l /tmp从容器拷贝文件到主机上
# docker cp 容器ID:容器内路径 目的主机路径
docker cp 04ac5ae5d5fb:/mnt/test.log /data1生成新镜像副本
# docker commit 提交容器副本成为一个新的镜像
# docker commit -m="描述" -a="作者" 容器ID 镜像名:版本
docker commit -m="my tomcat" -a="soul" 04ac5ae5d5fb soul/go:1.0运行自定义镜像
docker run -it -p 7777:8080 soul/tomcat:1.0指定端口运行
# docker run -it -p 主机端口:容器端口 tomcat
docker run -it -p 8081:8080 tomcat浏览器访问
http://localhost:8080随机分配主机端口
docker run -it -P tomcat后台运行
docker run -d -p 6666:8080 tomcat指定容器数据卷启动 (等于主机目录挂载到容器指定目录)
# docker run -it -v 主机目录:容器目录 镜像名
docker run -it -v /mydata:/mydata centos只读权限
docker run -it -v /mydata:/mydata:ro centos容器数据卷共享
docker run -it --name dc01 soul/centos
docker run -it --name dc02 --volumes-from dc01 soul/centos
docker run -it --name dc03 --volumes-from dc01 soul/centosRedis运行容器
docker run -p 6379:6379
-v /data1/redis/data:/data
-v /data1/redis/conf/redis.conf:/usr/locak/etc/redis/redis.conf
-d redis:5.0.10 redis-server /usr/local/etc/redis/redis.conf
--appendonly yesMySQL运行容器
docker run -p 12345:3306 --name mysql
-v /data1/mysql/conf:/etc/mysql/conf.d
-v /data1/mysql/logs:/logs
-v /data1/mysql/data:/var/lib/mysql
-e MYSQL_ROOT_PASSWORD=123456
-d mysql:5.6备份数据库
docker exec 04ac5ae5d5fb sh -C 'exec mysqldump --all-databases -uroot -p"123456"' > /data1/all-databases.sql读者福利:关注小编+转发文章+私信【项目】获取整理好的100+个Java项目视频+源码+笔记
提交镜像到阿里云
登录阿里云Docker Registry
$ sudo docker login --username=uisoul registry.cn-shenzhen.aliyuncs.com用于登录的用户名为阿里云账号全名,密码为开通服务时设置的密码。
您可以在访问凭证页面修改凭证密码。
从Registry中拉取镜像
$ sudo docker pull registry.cn-shenzhen.aliyuncs.com/uisoul/gocentos:[镜像版本号]将镜像推送到Registry
$ sudo docker login --username=uisoul registry.cn-shenzhen.aliyuncs.com
$ sudo docker tag [ImageId] registry.cn-shenzhen.aliyuncs.com/uisoul/gocentos:[镜像版本号]
$ sudo docker push registry.cn-shenzhen.aliyuncs.com/uisoul/gocentos:[镜像版本号]请根据实际镜像信息替换示例中的[ImageId]和[镜像版本号]参数。
作者:IM魂影
原文:imsoul.blog.csdn.net/article/details/110531103
相关推荐
-
- huifuqqcom 官方网站(huifu.qq.com)
-
qq恢复官方网站,http://huifu.qq.com/1、什么是QQ恢复系统?QQ恢复系统是腾讯公司提供的一项找回QQ联系人、QQ群的服务,向所有QQ用户免费开放。2、QQ恢复系统能恢复多长时间内删除的好友?普通用户可以申请恢复3个月内...
-
2025-12-19 16:51 off999
- 优启通u盘装win7(优启通重装win7)
-
如果安装windows7视窗操作系统,推荐使用ACHI硬盘模式,可以提高SATA硬盘的读写速度,比传统IDE模式大约提高了10%-30%。硬盘的读写速度提高,相对的噪音也会大一些,如果不需要进行大量数...
- pp助手苹果版下载安装(pp助手软件下载安装苹果)
-
Ipad上不能直接下载PP助手进行安装,会提示失败。方法如下:1.将Ipad用数据线与电脑连接,然后按照电脑端的pp助手。2.然后进入电脑端的pp助手,可以看到选项,安装pp助手到Ipad上。...
- 如何关闭uac(如何关闭uac权限)
-
1.使用电脑快捷键WIN+R打开运行窗口,窗口内输入"msconfig"。2.在打开的窗口选项卡中点击“工具”按钮,在下拉栏里找到“更改UAC通知”选项,点击下方的“启动”按钮。3...
- 轻启动激活码永久(轻启动解锁版)
-
如果您的WindowsXP轻启动一直无法激活,可能是由于多种原因导致的。首先,请确保您的网络连接正常,并且您的计算机的日期和时间设置正确。其次,确保您输入的产品密钥是正确的,并且与您的操作系统版本相...
- msdn下载系统靠谱吗(msdn下载安装)
-
秋叶系统好用,自动激活的,而且非常流畅。。。MSDN下载的系统驱动具有普遍兼容性,一般硬件商提供的更好MSDN下载的系统需要激活。原版系统意味着没有任何激活和授权,需要自己有激活密钥序列号,否则30...
- 赛格电脑城买电脑靠谱吗(赛格电脑城的电脑为什么便宜)
-
西安赛格电脑城的东西质量好,可信。1、赛格是整个西安,至整个陕西,乃至整个西北地区,最大的电子产品集散地,便宜实惠很靠谱。只要去到赛格正规的柜台去买东西产品,都没有问题。2、西安赛格电脑商城总建筑面积...
- ins加速器永久免费版(加速器免费加速steam)
-
①通常来说这种软件是为了让用户使用某些软件平台可以获得更好的使用体验而推出来的。②其次部分软件因某些原因。而不得不做出这种选择。③同时这种软件也会对用户在设备中使用的网络线路进行改善。让用户可以更好的...
-
- 系统集成项目管理工程师是干什么的
-
首先,有这个证书对于你从事IT行业有很大的好处。如果同样学历、同样经验的人员应聘同一家IT企业,如果你有这个证书,那么你的录取率将会大大地增加,同时你还可以为自己争取一个比较理想的薪水(前提是你确实是有一定的项目管理实践的基础上)。其次,可...
-
2025-12-19 12:03 off999
- 设置自动关机不显示提示窗口
-
一.首先我们要处理掉一个可能性到"我的电脑按"右键-->属性-->高级-->按下"启动及修复"-->把下面"系统失败"那框框的三个选项取消勾选.当把这三个选择取消后.能解决大部...
- win7安全模式进去也黑屏(win7安全模式黑屏只有鼠标能动)
-
分辨率设置超出范围或者显卡驱动有问题导致的。解决方法:1、开机按F8选择安全模式进入安全模式。2、在安全模式桌面用鼠标右键点我的电脑,属性,打开设备管理器,展开设备管理器,用鼠标右键选择显卡驱动卸载...
欢迎 你 发表评论:
- 一周热门
-
-
抖音上好看的小姐姐,Python给你都下载了
-
全网最简单易懂!495页Python漫画教程,高清PDF版免费下载
-
Python 3.14 的 UUIDv6/v7/v8 上新,别再用 uuid4 () 啦!
-
飞牛NAS部署TVGate Docker项目,实现内网一键转发、代理、jx
-
python入门到脱坑 输入与输出—str()函数
-
宝塔面板如何添加免费waf防火墙?(宝塔面板开启https)
-
Python三目运算基础与进阶_python三目运算符判断三个变量
-
(新版)Python 分布式爬虫与 JS 逆向进阶实战吾爱分享
-
失业程序员复习python笔记——条件与循环
-
系统u盘安装(win11系统u盘安装)
-
- 最近发表
- 标签列表
-
- python计时 (73)
- python安装路径 (56)
- python类型转换 (93)
- python进度条 (67)
- python吧 (67)
- python的for循环 (65)
- python格式化字符串 (61)
- python静态方法 (57)
- python列表切片 (59)
- python面向对象编程 (60)
- python 代码加密 (65)
- python串口编程 (77)
- python封装 (57)
- python写入txt (66)
- python读取文件夹下所有文件 (59)
- python操作mysql数据库 (66)
- python获取列表的长度 (64)
- python接口 (63)
- python调用函数 (57)
- python多态 (60)
- python匿名函数 (59)
- python打印九九乘法表 (65)
- python赋值 (62)
- python异常 (69)
- python元祖 (57)
