01.查看镜像 docker images
[root@i-rbj0ryi8 ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
rabbitmq management 813865544c51 6 months ago 253MB
redis latest bc8d70f9ef6c 12 months ago 105MB
02.搜索镜像 docker search 镜像名
[root@i-rbj0ryi8 ~]$ docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 12556 [OK] [OK]
03.下载镜像 docker pull 镜像名(若不指定镜像版本,默认会下载最新版)
[root@i-rbj0ryi8 ~]$ docker pull nginx:1.18.0
1.18.0: Pulling from library/nginx
f7ec5a41d630: Pull complete
04.删除镜像 docker rmi 镜像id
[root@i-rbj0ryi8 ~]$ docker rmi 605c77e624dd
Untagged: nginx:latest
Untagged: nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Deleted: sha256:605c77e624ddb75e6110f997c58876baa13f8754486b461117934b24a9dc3a85
04.提交镜像docker commit
[root@i-rbj0ryi8 ~]$ docker commit --help
Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Create a new image from a container's changes
Options:
-a, --author string Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
-c, --change list Apply Dockerfile instruction to the created image
-m, --message string Commit message
-p, --pause Pause container during commit (default true)
具体使用
[root@i-rbj0ryi8 ~]$ docker commit -a "mhzzj" -m "提交测试" 5826c3e8ae24 testnginxv1.0
sha256:234b8472f14bcaf3ec3548ae45b23c0c00d850ea5dc7e9960c63b71f0e05af25
[root@i-rbj0ryi8 ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
testnginxv1.0 latest 296b0b6f698d 3 minutes ago 182MB
[root@i-rbj0ryi8 ~]$ docker run -d -p 80:80 testnginxv1.0
e85dcdf5f7d2870d9f6724bdf0ca15c8f0a2a0ce26716e6627cfdca430d14732
05.镜像持久化docker save
[root@i-rbj0ryi8 ~]$ docker save -o savedemo.tar testnginxv1.0
[root@i-rbj0ryi8 ~]$ ls
savedemo.tar
[root@i-rbj0ryi8 ~]$ docker load -i savedemo.tar
Loaded image: testnginxv1.0:latest
06.镜像推送docker push
-
先注册dockerhub: https://login.docker.com/u/login/
-
并且创建仓库
-
登录docker
[root@i-rbj0ryi8 ~]$ 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: mhzzj
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/
Login Succeeded
-
推送镜像
[root@i-rbj0ryi8 ~]$ docker push mhzzj/pushdemo:testnginxv1.0
The push refers to repository [docker.io/mhzzj/pushdemo]
An image does not exist locally with the tag: mhzzj/pushdemo
报错:原因:没有给镜像打标签
打标签
[root@i-rbj0ryi8 ~]$ docker tag testnginxv1.0 mhzzj/pushdemo:mytagv1.0
[root@i-rbj0ryi8 ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
testnginxv1.0 latest 3b490214c1e9 8 minutes ago 133MB
mhzzj/pushdemo mytagv1.0 3b490214c1e9 8 minutes ago 133MB
nginx 1.18.0 c2c45d506085 14 months ago 133MB
推送
[root@i-rbj0ryi8 ~]$ docker push mhzzj/pushdemo:mytagv1.0
The push refers to repository [docker.io/mhzzj/pushdemo]
53faf37c6825: Pushed
4fa6704c8474: Mounted from library/nginx
4fe7d87c8e14: Mounted from library/nginx
6fcbf7acaafd: Mounted from library/nginx
f3fdf88f1cb7: Mounted from library/nginx
7e718b9c0c8c: Mounted from library/nginx
mytagv1.0: digest: sha256:ed36473195f7c116dcc6424bc54e27214a8bf8efd02dbc05103ce319316f2f68 size: 1570
推送成功
5. 下载推送的镜像
[root@i-rbj0ryi8 ~]$ docker pull mhzzj/pushdemo:mytagv1.0
mytagv1.0: Pulling from mhzzj/pushdemo
f7ec5a41d630: Already exists
0b20d28b5eb3: Already exists
1576642c9776: Already exists
c12a848bad84: Already exists
03f221d9cf00: Already exists
7702790ca7b1: Already exists
Digest: sha256:ed36473195f7c116dcc6424bc54e27214a8bf8efd02dbc05103ce319316f2f68
Status: Downloaded newer image for mhzzj/pushdemo:mytagv1.0
docker.io/mhzzj/pushdemo:mytagv1.0
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)