Docker常用基础命令
docker常用命令的总结
·
目录
1、docker version 查看版本信息
[root@k8s-master01 ~]# docker version
Client: Docker Engine - Community ## 客户端版本
Version: 20.10.14
API version: 1.40
Go version: go1.16.15 ## docker使用go语言开发
Git commit: a224086
Built: Thu Mar 24 01:49:57 2022
OS/Arch: linux/amd64 ## 系统架构
Context: default
Experimental: true
Server: Docker Engine - Community ## 服务端版本
Engine:
Version: 19.03.15
API version: 1.40 (minimum version 1.12)
Go version: go1.13.15
Git commit: 99e3ed8919
Built: Sat Jan 30 03:16:33 2021
OS/Arch: linux/amd64
Experimental: false
containerd: ## containerd版本
Version: 1.5.11
GitCommit: 3df54a852345ae127d1fa3092b95168e4a88e2f8
runc: ## docker引擎
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
docker-init:
Version: 0.18.0
GitCommit: fec3683
2、docker info 查看docker的一些信息
[root@k8s-master01 ~]# docker info
Client:
Context: default
Debug Mode: false ## 可以查看docker有没有开启debug
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.8.1-docker)
scan: Docker Scan (Docker Inc., v0.17.0)
Server:
Containers: 11 # 这台宿主机运行了多少个容器
Running: 4 # 运行中的容器
Paused: 0
Stopped: 7 # 停止的容器
Images: 8 # 镜像的数量
Server Version: 19.03.15
Storage Driver: overlay2 # 存储的驱动 aufs、overlay、brtfs
Backing Filesystem: xfs #
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
## 日志的存储类型,json-file日志会存在本地
[root@k8s-master01 ~]# cd /var/lib/docker
[root@k8s-master01 docker]# ls
builder buildkit containers image network overlay2 plugins runtimes swarm tmp trust volumes
[root@k8s-master01 docker]# cd containers/
[root@k8s-master01 containers]# ls
087b8d2d0bd512e319fbb13f1b7f508e8a5c57260260bbab0ce1cf0ecb8959d1 658a74e5b2ed0f8beac6d5854a94ab3a8cef9fa5df7eecded31a4f47e403d834
0aa9faa8f0ff0aed93cf44989b9bcdb93fdec6b21103d96e5d31e3db405f96d8 b035503ff239804c1ee1ccaf751dd56838017ac8502d5a888ef136a6bad3b8c0
0fd052f2faf065ee8871e52e3015292f4ffcce8b26655cd181a6c2d6dd7ba3e4 b4b98e10a629dff5ad2dc17a2f9128319b39b7e04537170c074d5446c574c76e
1196086f0f7e612dcf5f257a21e92872c63ce9a1c90fdf3fe886c93e123997fe d203af1bf681f58f80609804dea3eba743be390fb4b291373a633af559677d5a
582362b59be13204de82e3030ed654ed14c53b050b21424941ec62d7a13064f8 db76c3b54116bba9fff76a1730fe6ba63c85d05631b70f65a3d14dcebcd9a942
5acceb3a8f22942058d18643f0f5b16da2c8aada58439e009150bb4504cf70c0
[root@k8s-master01 containers]# cd 087b8d2d0bd512e319fbb13f1b7f508e8a5c57260260bbab0ce1cf0ecb8959d1/
[root@k8s-master01 087b8d2d0bd512e319fbb13f1b7f508e8a5c57260260bbab0ce1cf0ecb8959d1]# ls
087b8d2d0bd512e319fbb13f1b7f508e8a5c57260260bbab0ce1cf0ecb8959d1-json.log checkpoints config.v2.json hostconfig.json mounts
[root@k8s-master01 087b8d2d0bd512e319fbb13f1b7f508e8a5c57260260bbab0ce1cf0ecb8959d1]# tail -f 087b8d2d0bd512e319fbb13f1b7f508e8a5c57260260bbab0ce1cf0ecb8959d1-json.log
## docker容器进行重启之后,日志就会被清空。以最干净的方式运行
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
# Logging Driver可以更改成以上项。
Swarm: inactive # inactive没有启动,active启动
Runtimes: runc # 用来运行容器的一个标准,docker给予runc来创建的。
Default Runtime: runc
Init Binary: docker-init
containerd version: 3df54a852345ae127d1fa3092b95168e4a88e2f8
runc version: v1.0.3-0-gf46b6ba
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-693.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.781GiB
Name: k8s-master01
ID: A7ZM:BAK2:OBV7:O62Z:USHJ:LQGH:FFPC:IZ4M:WIHF:572R:5UT6:OIRX
Docker Root Dir: /var/lib/docker
## 此路径可以修改,生产环境的最好挂一块ssd盘,单独存储。最次也要使用单独的磁盘进行挂载,不可以和宿主机公用,会把根分区、系统分区干满
Debug Mode: false
Registry: https://index.docker.io/v1/ ## 镜像仓库地址,如果自己有镜像仓库,可以更改
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
3、docker search 镜像搜索
[root@k8s-master01 ~]# docker search centos ## OFFICIAL为ok是指官方的镜像
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 7111 [OK]
centos/systemd systemd enabled base container. 108 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 93
centos/postgresql-96-centos7 PostgreSQL is an advanced Object-Relational … 45
centos/httpd-24-centos7 Platform for running Apache httpd 2.4 or bui… 44
centos/python-35-centos7 Platform for building and running Python 3.5… 39
centos/php-56-centos7 Platform for building and running PHP 5.6 ap… 34
centos/mysql-56-centos7 MySQL 5.6 SQL database server 22
centos/postgresql-10-centos7 PostgreSQL is an advanced Object-Relational … 19
kasmweb/centos-7-desktop CentOS 7 desktop for Kasm Workspaces 18
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 16
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 13
centos/mariadb-101-centos7 MariaDB 10.1 SQL database server 13
centos/mongodb-36-centos7 MongoDB NoSQL database server 8
centos/redis-32-centos7 Redis in-memory data structure store, used a… 6
centos/mariadb-102-centos7 MariaDB 10.2 SQL database server 6
centos/mongodb-34-centos7 MongoDB NoSQL database server 3
centos/ruby-25-centos7 Platform for building and running Ruby 2.5 a… 3
continuumio/centos5_gcc5_base 3
kasmweb/core-centos-7 CentOS 7 base image for Kasm Workspaces 2
ibmcom/fhe-toolkit-centos-amd64 The IBM Fully Homomorphic Encryption (FHE) T… 0
ibmcom/fhe-toolkit-centos The IBM Fully Homomorphic Encryption (FHE) T… 0
bitnami/centos-extras-base 0
bitnami/centos-base-buildpack Centos base compilation image 0 [OK]
datadog/centos-i386 0
4、docker pull 拉取镜像到本地
[root@k8s-master01 ~]# docker pull alpine:latest
latest: Pulling from library/alpine
df9b9388f04a: Pull complete
Digest: sha256:4edbd2beb5f78b1014028f4fbb99f3237d9561100b6881aabbf5acce2c4f9454
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
# 如果本地有此镜像,就不会重复拉取
[root@k8s-master01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 0ac33e5f5afa 2 weeks ago 5.57MB
5、docker push 推送本地的镜像到镜像仓库
[root@k8s-master01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dotbalo/coredns 1.3.1 eb516548c180 3 years ago 40.3MB
k8s.gcr.io/coredns 1.3.1 eb516548c180 3 years ago 40.3MB
#推送前需要登录到docker的镜像仓库,也可以docker login xxx.com 登录指定的镜像仓库,例如阿里等。
[root@k8s-master01 ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: dotbalo
Password:
[root@k8s-master01 ~]# docker push dotbalo/coredns:1.3.1
The push refers to repository [docker.io/dotbalo/coredns]
c6a5fc8a3f01: Preparing
fb61a074724d: Preparing
6、docker tag 修改镜像标签
[root@k8s-master01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
k8s.gcr.io/coredns 1.3.1 eb516548c180 3 years ago 40.3MB
[root@k8s-master01 ~]# docker tag k8s.gcr.io/coredns:1.3.1 dotbalo/coredns:1.3.1
[root@k8s-master01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dotbalo/coredns 1.3.1 eb516548c180 3 years ago 40.3MB
k8s.gcr.io/coredns 1.3.1 eb516548c180 3 years ago 40.3MB
7、docker run 启动镜像
docker run -i -t <IMAGE_ID> /bin/bash:-i:标准输入给容器
-t:分配一个虚拟终端 /bin/bash:执行bash脚本
-i:交互式运行
-d:以守护进程方式运行(后台)
-P:默认匹配docker容器的5000端口号到宿主机的49153 to 65535端口
-p <HOT_PORT>:<CONTAINER_PORT>:指定端口号
- -name: 指定容器的名称
- -rm:退出时删除容器
示例:前台启动
[root@ls_rflrhksm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 0ac33e5f5afa 3 weeks ago 5.57MB
centos 8 5d0da3dc9764 7 months ago 231MB
[root@ls_rflrhksm ~]# docker run -it centos:8 /bin/bash
[root@c9293d01a5b5 /]#
[root@ls_rflrhksm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 0ac33e5f5afa 3 weeks ago 5.57MB
centos 8 5d0da3dc9764 7 months ago 231MB
nginx 1.14.2 295c7be07902 3 years ago 109MB
#### 前台启动nginx,并将容器的12345端口映射到宿主机的80端口上。
[root@ls_rflrhksm ~]# docker run -ti -p 12345:80 nginx:1.14.2
111.197.249.16 - - [29/Apr/2022:03:35:01 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.
36" "-"2022/04/29 03:35:01 [error] 6#6: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 111.197.249.16, server: localhost, request: "GET /favicon.ico HTT
P/1.1", host: "120.48.23.240:12345", referrer: "http://120.48.23.240:12345/"111.197.249.16 - - [29/Apr/2022:03:35:01 +0000] "GET /favicon.ico HTTP/1.1" 404 571 "http://120.48.23.240:12345/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gec
ko) Chrome/100.0.4896.127 Safari/537.36" "-"
## 页面访问:120.48.23.240:12345
示例:后台启动
[root@ls_rflrhksm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 0ac33e5f5afa 3 weeks ago 5.57MB
centos 8 5d0da3dc9764 7 months ago 231MB
[root@ls_rflrhksm ~]# docker run -d centos:8 /bin/bash
4b103bbe802702f6f6a948a844229d129a37b3a1e804c799ca67018593715520
[root@ls_rflrhksm ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4b103bbe8027 centos:8 "/bin/bash" 6 seconds ago Exited (0) 5 seconds ago lucid_moore
8、docker logs 查看容器日志
格式:
docker logs <CONTAINER_ID> : 输出容器日志
-f:实时输出
示例:
[root@ls_rflrhksm ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a813ef53b4e centos:8 "/bin/bash" 4 seconds ago Up 4 seconds admiring_tharp
[root@ls_rflrhksm ~]# docker logs -f 9a813ef53b4e
9、docker ps 查看正在运行的容器
docker ps:
[root@ls_rflrhksm ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a813ef53b4e centos:8 "/bin/bash" 8 minutes ago Up 8 minutes admiring_thar
docker ps -l 显示最后启动的容器:
[root@ls_rflrhksm ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a813ef53b4e centos:8 "/bin/bash" 8 minutes ago Up 8 minutes admiring_tharp
docker ps -a 同时显示停止的容器,默认只显示启动状态:
[root@ls_rflrhksm ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a813ef53b4e centos:8 "/bin/bash" 9 minutes ago Up 9 minutes admiring_tharp
4b103bbe8027 centos:8 "/bin/bash" 20 minutes ago Exited (0) 20 minutes ago lucid_moore
291fd0d9413f nginx:1.14.2 "sh" 22 minutes ago Exited (0) 20 minutes ago vigorous_kirch
c9293d01a5b5 centos:8 "/bin/bash" 24 minutes ago Exited (0) 24 minutes ago eager_ellis
docker ps -q 查看正在运行容器的ID:
[root@ls_rflrhksm ~]# docker ps -q
9a813ef53b4e
docker ps -aq 查看所有容器的ID,包括停止和正在运行的:
[root@ls_rflrhksm ~]# docker ps -aq
9a813ef53b4e
4b103bbe8027
291fd0d9413f
c9293d01a5b5
10、docker exec 进入到正在运行的容器、
格式:
docker exec -it <CONTAINER_ID> bash 连接到启动的容器
示例:
[root@ls_rflrhksm ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a813ef53b4e centos:8 "/bin/bash" 30 minutes ago Up 30 minutes admiring_tharp
[root@ls_rflrhksm ~]# docker exec -ti 9a813ef53b4e sh
sh-4.4#
11、docker cp 拷贝
11.1 把宿主机文件拷贝到容器中
格式:
docker cp hostpath <CONTAINER_ID>:path
示例:
[root@ls_rflrhksm ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cae36790ca57 nginx:1.14.2 "nginx -g 'daemon of…" 5 minutes ago Up 5 minutes 0.0.0.0:12345->80/tcp dreamy_bhaskara
9a813ef53b4e centos:8 "/bin/bash" 46 minutes ago Up 46 minutes admiring_tharp
[root@ls_rflrhksm ~]# echo "lllxxx" >inde.html
[root@ls_rflrhksm ~]# docker exec -ti cae36790ca57 bash
root@cae36790ca57:/# cd /usr/share/nginx/html/
root@cae36790ca57:/usr/share/nginx/html# ls
50x.html index.html
root@cae36790ca57:/usr/share/nginx/html# exit
exit
[root@ls_rflrhksm ~]# docker cp inde.html cae36790ca57:/usr/share/nginx/html/
[root@ls_rflrhksm ~]# docker exec -ti cae36790ca57 bash
root@cae36790ca57:/# ls /usr/share/nginx/html/
50x.html inde.html index.html
root@cae36790ca57:/#
11.2 把容器中的文件拷贝到宿主机
格式:
docker cp <CONTAINER_ID>:path hostpath
示例:
[root@ls_rflrhksm ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cae36790ca57 nginx:1.14.2 "nginx -g 'daemon of…" 5 minutes ago Up 5 minutes 0.0.0.0:12345->80/tcp dreamy_bhaskara
9a813ef53b4e centos:8 "/bin/bash" 46 minutes ago Up 46 minutes admiring_tharp
[root@ls_rflrhksm ~]# docker cp cae36790ca57:/usr/share/nginx/html/index.html .
[root@ls_rflrhksm ~]# ls
inde.html index.html
12、docker rmi 删除本地镜像
格式:
docker rmi IMAGE ID
示例:
[root@ls_rflrhksm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 0ac33e5f5afa 3 weeks ago 5.57MB
centos 8 5d0da3dc9764 7 months ago 231MB
nginx 1.14.2 295c7be07902 3 years ago 109MB
[root@ls_rflrhksm ~]# docker rmi 0ac33e5f5afa
Untagged: alpine:latest
Untagged: alpine@sha256:4edbd2beb5f78b1014028f4fbb99f3237d9561100b6881aabbf5acce2c4f9454
Deleted: sha256:0ac33e5f5afa79e084075e8698a22d574816eea8d7b7d480586835657c3e1c8b
Deleted: sha256:4fc242d58285699eca05db3cc7c7122a2b8e014d9481f323bd9277baacfa0628
[root@ls_rflrhksm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 8 5d0da3dc9764 7 months ago 231MB
nginx 1.14.2 295c7be07902 3 years ago 109MB
删除所有镜像:
docker rmi `docker images -q -a`
13、docker rm 删除容器
格式:
docker rm CONTAINER ID
示例:
[root@ls_rflrhksm ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cae36790ca57 nginx:1.14.2 "nginx -g 'daemon of…" 22 minutes ago Up 22 minutes 0.0.0.0:12345->80/tcp dreamy_bhaskara
9a813ef53b4e centos:8 "/bin/bash" About an hour ago Up About an hour admiring_tharp
c9293d01a5b5 centos:8 "/bin/bash" About an hour ago Exited (0) About an hour ago eager_ellis
[root@ls_rflrhksm ~]# docker rm c9293d01a5b5
c9293d01a5b5
[root@ls_rflrhksm ~]# docker ps -a | grep c9293d01a5b5
[root@ls_rflrhksm ~]#
删除所有容器:
docker rm `docker ps -a -q`:删除所有容器
14、docker stop 停止容器
格式:
docker stop <CONTAINER_ID>
示例:
[root@ls_rflrhksm ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cae36790ca57 nginx:1.14.2 "nginx -g 'daemon of…" 32 minutes ago Up 32 minutes 0.0.0.0:12345->80/tcp dreamy_bhaskara
9a813ef53b4e centos:8 "/bin/bash" About an hour ago Up About an hour admiring_tharp
[root@ls_rflrhksm ~]# docker stop cae36790ca57
cae36790ca57
[root@ls_rflrhksm ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cae36790ca57 nginx:1.14.2 "nginx -g 'daemon of…" 32 minutes ago Exited (0) 2 seconds ago dreamy_bhaskara
15、docker start 重新启动容器
格式:
docker start <CONTAINER_ID>
示例:
[root@ls_rflrhksm ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cae36790ca57 nginx:1.14.2 "nginx -g 'daemon of…" 32 minutes ago Exited (0) 2 seconds ago dreamy_bhaskara
[root@ls_rflrhksm ~]# docker start cae36790ca57
cae36790ca57
[root@ls_rflrhksm ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cae36790ca57 nginx:1.14.2 "nginx -g 'daemon of…" 34 minutes ago Up 2 seconds 0.0.0.0:12345->80/tcp dreamy_bhaskara
16、docker history 查看镜像更改记录
格式:
docker history REPOSITORY:TAG
示例:
[root@ls_rflrhksm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 8 5d0da3dc9764 7 months ago 231MB
nginx 1.14.2 295c7be07902 3 years ago 109MB
[root@ls_rflrhksm ~]# docker history nginx:1.14.2
IMAGE CREATED CREATED BY SIZE COMMENT
295c7be07902 3 years ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B
<missing> 3 years ago /bin/sh -c #(nop) STOPSIGNAL SIGTERM 0B
<missing> 3 years ago /bin/sh -c #(nop) EXPOSE 80 0B
<missing> 3 years ago /bin/sh -c ln -sf /dev/stdout /var/log/nginx… 22B
<missing> 3 years ago /bin/sh -c set -x && apt-get update && apt… 53.8MB
<missing> 3 years ago /bin/sh -c #(nop) ENV NJS_VERSION=1.14.2.0.… 0B
<missing> 3 years ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.14.2-… 0B
<missing> 3 years ago /bin/sh -c #(nop) LABEL maintainer=NGINX Do… 0B
<missing> 3 years ago /bin/sh -c #(nop) CMD ["bash"] 0B
<missing> 3 years ago /bin/sh -c #(nop) ADD file:4fc310c0cb879c876… 55.3MB
17、docker commit 从容器创建一个新的镜像
格式:
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
OPTIONS说明:
-a :提交的镜像作者;
-c :使用Dockerfile指令来创建镜像;
-m :提交时的说明文字;
-p :在commit时,将容器暂停。
示例:
[root@ls_rflrhksm ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cae36790ca57 nginx:1.14.2 "nginx -g 'daemon of…" 44 minutes ago Up 10 minutes 0.0.0.0:12345->80/tcp dreamy_bhaskara
[root@ls_rflrhksm ~]# docker commit -a "lixin" -m "new" cae36790ca57 nginx:lixin
sha256:08be2a66df25e18ea934e1b915b1d1c932e68c5f045f21d1ad0640c13fe1dff1
[root@ls_rflrhksm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx lixin 08be2a66df25 6 seconds ago 109MB
centos 8 5d0da3dc9764 7 months ago 231MB
nginx 1.14.2 295c7be07902 3 years ago 109MB
18、docker images 列出镜像
格式:
docker image
示例:
[root@ls_rflrhksm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx lixin 08be2a66df25 6 seconds ago 109MB
centos 8 5d0da3dc9764 7 months ago 231MB
nginx 1.14.2 295c7be07902 3 years ago 109MB
19、docker save 保存镜像
格式:
docker save
示例:
[root@ls_rflrhksm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7.6 init da765b31bbfb 9 days ago 202MB
120.48.23.240/c-lixin/ubuntu v22.04 df5de72bdb3b 6 weeks ago 77.8MB
保存到当前位置:
[root@ls_rflrhksm ~]# docker save -o ubuntu.tar 120.48.23.240/c-lixin/ubuntu:v22.04
[root@ls_rflrhksm ~]# ls
docker_file shell ubuntu.tar
保存到指定位置:
[root@ls_rflrhksm ~]# docker save > /opt/ubuntu.tar 120.48.23.240/c-lixin/ubuntu:v22.04
[root@ls_rflrhksm ~]# ls /opt/
avalokita bcm-agent bsm-agent containerd hosteye rh ubuntu.tar
20、docker load上传保存后的镜像
格式:
docker load [OPTIONS]
--input , -i : 指定导入的文件,代替 STDIN。
--quiet , -q : 精简输出信息。
示例:
[root@ls_rflrhksm ~]# ls
docker_file shell ubuntu.tar
[root@ls_rflrhksm ~]# docker load --input ubuntu.tar
629d9dbab5ed: Loading layer [==================================================>] 80.35MB/80.35MB
Loaded image: 120.48.23.240/c-lixin/ubuntu:v22.04
[root@ls_rflrhksm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7.6 init da765b31bbfb 9 days ago 202MB
120.48.23.240/c-lixin/ubuntu v22.04 df5de72bdb3b 6 weeks ago 77.8MB
[root@ls_rflrhksm ~]# docker load < ubuntu.tar
629d9dbab5ed: Loading layer [==================================================>] 80.35MB/80.35MB
Loaded image: 120.48.23.240/c-lixin/ubuntu:v22.04
[root@ls_rflrhksm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7.6 init da765b31bbfb 9 days ago 202MB
120.48.23.240/c-lixin/ubuntu v22.04 df5de72bdb3b 6 weeks ago 77.8MB
更多推荐
已为社区贡献1条内容
所有评论(0)