新手快速入门Docker,轻松掌握Docker安装与使用
off999 2025-01-13 16:49 26 浏览 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
相关推荐
- 戴尔官网保修查询入口(戴尔售后保质期查询)
-
可以按照以下步骤查询戴尔笔记本电脑的保修期:1.打开戴尔官网:https://www.戴尔.com/zh-cn/售后服务/保修政策.html2.点击页面上方的“服务与支持”按钮,进入戴尔的服务支持...
- 手机号邮箱登录入口(手机号邮箱官网)
-
手机163邮箱登录入口如下:163邮箱官网入口:https://smart.mail.163.com/login.htm点击进入登录或者注册邮箱即可。手机浏览器访问进入官网http://www.123...
- sd卡(sd卡无法读取怎么修复)
-
SD卡是大卡,相机用的;普通的手机内存卡,是小卡,正规的名称是macrosd卡,也就是微型SD卡。可以通过卡套转为普通的SD卡的大小。 其实就是大小不同。但手机上的内存卡,人们经常也俗称为SD...
- windows7蓝牙功能在哪里打开
-
点击搜索框在windows7系统主界面点击开始菜单,点击打开搜索框。输入命令输入services.msc后回车,在列表中找到并右击BluetoothSupportS...点击属性选择进入属性菜单,...
-
- 2010激活密钥(microsoft2010激活密钥)
-
步骤/方式1officeprofessionalplus2010:(office专业版)6QFdx-pYH2G-ppYFd-C7RJM-BBKQ8Bdd3G-xM7FB-Bd2HM-YK63V-VQFdKVYBBJ-TRJpB-QFQ...
-
2025-11-19 04:03 off999
- 联想官方刷新bios工具(联想电脑刷新bios)
-
刷新BIOS需要使用联想的官方网站或授权维修中心来进行操作。以下是一些基本步骤:1.访问联想的官方网站,找到BIOS更新程序并下载。在下载过程中,请确保选择与您计算机型号匹配的版本。2.将下载的B...
-
- 苹果ios14系统下载(苹果ios14.1下载)
-
1方法一步骤/方式一打开Appstore。步骤/方式二在搜索栏点击搜索框。步骤/方式三搜索并点击需要下载的软件。步骤/方式四点击获取。步骤/方式五最后验证ID密码即可。1.在应用商店搜索你要下载的应用名称。2.点击下载按钮,如果要求登...
-
2025-11-19 03:03 off999
- office2010怎么免费永久激活密钥
-
用这个试试,一个KMS激活工具可以激活2010到2019的Office自家的目前用的就是这个microsoft6477.moe/1716.html直接使用这个Microsoftoffice2010...
-
- 类似爱加速的国内ip(类似爱加速的app)
-
推荐“V8盒子”。这一款免费无广告的模拟器,不同于其它软件盒子,而是类似于X8沙箱,满足游戏多开,画中画,悬浮球操作,熄屏后台运行等多功能的沙箱盒子.支持一键root,一键安装xposed框架,能在安卓/苹果手机上运行多个安卓/ios虚拟系...
-
2025-11-19 02:03 off999
- 阿里旺旺手机客户端(阿里旺旺手机app)
-
手机淘宝的旺旺在打开商品后,会看到左下角有个旺旺的图标,点击就可以联系了。 阿里旺旺是将原先的淘宝旺旺与阿里巴巴贸易通整合在一起的一个新品牌。它是淘宝和阿里巴巴为商人量身定做的免费网上商务沟通软件,...
- 最纯净的pe装机工具(pe工具哪个纯净)
-
U盘装系统步骤:1.制作U盘启动盘。这里推荐大白菜U盘启动盘制作工具,在网上一搜便是。2.U盘启动盘做好了,我们还需要一个GHOST文件,可以从网上下载一个ghost版的XP/WIN7/WIN8系统,...
- 装一个erp系统多少钱(wms仓库管理软件)
-
现在主流有客户端ERP和云端ERP两种客户端通常一次买断,价格在万元左右,但是还有隐性费用,你需要支付服务器、数据管理员,此外如果系统需要更新维护,你还需要支付另外一笔不菲的费用。云端ERP:优势...
- cad2014序列号和密钥永久(autocad2014序列号和密钥)
-
1在cad2014中修改标注样式后,需要将其保存2单击“样式管理器”按钮,在弹出的窗口中选择修改后的标注样式,然后单击“设置为当前”按钮,再单击“保存当前样式”按钮,将其保存为新的样式名称3为了...
- qq修改密保手机号(qq修改密保手机号是什么意思)
-
QQ更改绑定的手机号码操作步骤如下:1、打开手机主界面,找到“QQ”软件点击打开。2、输入正确的QQ账户和密码登录到qq主界面。3、点击左上角的头像“图片”,进入到个人中心界面。4、进入到个人中心界面...
欢迎 你 发表评论:
- 一周热门
-
-
抖音上好看的小姐姐,Python给你都下载了
-
全网最简单易懂!495页Python漫画教程,高清PDF版免费下载
-
Python 3.14 的 UUIDv6/v7/v8 上新,别再用 uuid4 () 啦!
-
python入门到脱坑 输入与输出—str()函数
-
飞牛NAS部署TVGate Docker项目,实现内网一键转发、代理、jx
-
宝塔面板如何添加免费waf防火墙?(宝塔面板开启https)
-
Python三目运算基础与进阶_python三目运算符判断三个变量
-
(新版)Python 分布式爬虫与 JS 逆向进阶实战吾爱分享
-
慕ke 前端工程师2024「完整」
-
失业程序员复习python笔记——条件与循环
-
- 最近发表
- 标签列表
-
- 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)
