docker的镜像管理

docker镜像管理命令 --help

root@ubuntu-3:~# docker image --help

Usage:  docker image COMMAND

Manage images

Commands:
  build       Build an image from a Dockerfile
  history     Show the history of an image
  import      Import the contents from a tarball to create a filesystem image
  inspect     Display detailed information on one or more images
  load        Load an image from a tar archive or STDIN
  ls          List images
  prune       Remove unused images
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rm          Remove one or more images
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

查看当前本地的镜像

root@ubuntu-3:~# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
nginx        alpine    cc44224bfe20   10 months ago   23.5MB
ubuntu       22.04     9d28ccdc1fc7   10 months ago   76.3MB

拉取镜像

root@ubuntu-3:~# docker pull ubuntu:22.04
22.04: Pulling from library/ubuntu
Digest: sha256:f154feaf13b51d16e2b4b5575d69abc808da40c4b80e3a5055aaa4bcc5099d5b
Status: Image is up to date for ubuntu:22.04
docker.io/library/ubuntu:22.04

查看镜像的详细信息

root@ubuntu-3:~# docker image inspect nginx:alpine

删除本地镜像

root@ubuntu-3:~# docker rmi nginx:alpine

对镜像从新tag

root@ubuntu-3:~# docker tag nginx:alpine wuyang-nginx:v1
root@ubuntu-3:~# docker image ls | grep wuyang-nginx
wuyang-nginx   v1        cc44224bfe20   10 months ago   23.5MB

保存一个镜像到一个tar包

root@ubuntu-3:~# docker save nginx:alpine > wuyang-nginx-save.tar.gz
root@ubuntu-3:~# ls -la | grep wuyang-nginx-save
-rw-r--r--  1 root root 25002496 10月 28 15:02 wuyang-nginx-save.tar.gz

从一个tar包导入镜像

root@ubuntu-3:~# docker load -i wuyang-nginx-save.tar.gz 
Loaded image: nginx:alpine

查看一个镜像

root@ubuntu-3:~# docker search nginx | grep Official
nginx                                             Official build of Nginx.                        17586     [OK] 

从Dockerfile文件构建新的镜像

root@ubuntu-3:~/dockfile# cat Dockerfile 
FROM nginx:alpine
LABEL author="wuyang"
root@ubuntu-3:~/dockfile# docker build -t wuyang-build-image:v1 -f Dockerfile .

上传镜像到仓库

root@ubuntu-3:~# docker login -u wuyang1
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
root@ubuntu-3:~# docker tag nginx:alpine docker.io/wuyang1/nginx-push:v1
root@ubuntu-3:~# docker push docker.io/wuyang1/nginx-push:v1
The push refers to repository [docker.io/wuyang1/nginx-push]
419df8b60032: Pushed 
0e835d02c1b5: Pushed 
5ee3266a70bd: Pushed 
3f87f0a06073: Pushed 
1c9c1e42aafa: Pushed 
8d3ac3489996: Pushed 
v1: digest: sha256:544ba2bfe312bf2b13278495347bb9381ec342e630bcc8929af124f1291784bb size: 1568
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值