0


Docker 基础命令讲解实例(镜像)

1.启动Docker

  1. [root@localhost ~]# systemctl status docker
  2. docker.service - Docker Application Container Engine
  3. Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
  4. Active: inactive (dead)
  5. Docs: https://docs.docker.com
  6. [root@localhost ~]# systemctl start docker
  7. [root@localhost ~]# systemctl enable docker
  8. Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

2.镜像=>仓库

镜像存放在仓库,下载镜像,创建生成容器。

容器(对象,动态)

1)镜像信息查看

docker images 可以列出本地仓库存储的镜像。

实例:

  1. [root@localhost ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. nginx latest c316d5a335a5 4 weeks ago 142MB

字段解释:

PEPOSITORY ---表示镜像的仓库源

TAG ---镜像的标签

IMAGE ID ---镜像ID

CREATED --- 镜像创建时间

SIZE ---镜像大小

docker images [选项] [镜像名字][:TAG]

-a 显示仓库所有镜像

-f 按条件检索镜像

-q 显示镜像ID

  1. Flag shorthand -h has been deprecated, please use --help
  2. Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
  3. List images
  4. Options:
  5. -a, --all Show all images (default hides intermediate images)
  6. --digests Show digests
  7. -f, --filter filter Filter output based on conditions provided
  8. --format string Pretty-print images using a Go template
  9. --no-trunc Don't truncate output
  10. -q, --quiet Only show numeric IDs

2)获取镜像

docker pull [选项][name][:TAG@DIGEST]

镜像名字 + 版本 --不加版本默认最新版本

实例:

  1. 获取centos最新
  2. centos:latest
  3. [root@localhost ~]# docker pull centos:latest
  4. latest: Pulling from library/centos
  5. a1d0c7532777: Pull complete
  6. Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
  7. Status: Downloaded newer image for centos:latest

docker images 查看新下载镜像

  1. 指定镜像名字
  2. [root@localhost ~]# docker images centos
  3. REPOSITORY TAG IMAGE ID CREATED SIZE
  4. centos latest 5d0da3dc9764 5 months ago 231MB

3)镜像查找

  1. docker search [OPTIONS] TERM 查找仓库中
  2. -f 过滤查找需要镜像

实例:

  1. [root@localhost ~]# docker search ubuntu
  2. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
  3. ubuntu/nginx Nginx, a high-performance reverse proxy & we 33
  4. ubuntu/mysql MySQL open source fast, stable, multi-thread 24
  5. ubuntu/apache2 Apache, a secure & extensible open-source HT 23
  6. ubuntu/prometheus Prometheus is a systems and service monitori 23
  7. kasmweb/ubuntu-bionic-desktop Ubuntu productivity desktop for Kasm Workspa 18
  8. ubuntu/postgres PostgreSQL is an open source object-relation 13
  9. ubuntu/squid Squid is a caching proxy for the Web. Long-t 12
  10. ubuntu/bind9 BIND 9 is a very flexible, full-featured DNS 12
  11. ubuntu/redis Redis, an open source key-value store. Long-… 8
  12. ubuntu/prometheus-alertmanager Alertmanager handles client alerts from Prom 5
  13. ubuntu/grafana Grafana, a feature rich metrics dashboard & 5
  14. ubuntu/telegraf Telegraf collects, processes, aggregates & w 3
  15. circleci/ubuntu-server This image is for internal use 3
  16. ubuntu/memcached Memcached, in-memory keyvalue store for smal 3
  17. ubuntu/cortex Cortex provides storage for Prometheus. Long 2
  18. ubuntu/cassandra Cassandra, an open source NoSQL distributed 1
  19. ubuntu Ubuntu is a Debian-based Linux operating sys 0 [OK]
  20. ubuntu-upstart DEPRECATED, as is Upstart (find other proces 0 [OK]
  21. neurodebian NeuroDebian provides neuroscience research s 0 [OK]
  22. open-liberty Open Liberty multi-architecture images based 0 [OK]
  23. ubuntu-debootstrap DEPRECATED; use "ubuntu" instead 0 [OK]
  24. bitnami/ubuntu-base-buildpack Ubuntu base compilation image 0 [OK]
  25. websphere-liberty WebSphere Liberty multi-architecture images 0 [OK]
  26. snyk/ubuntu A base ubuntu image for all broker clients t 0
  27. rancher/ubuntuconsole 0

4)镜像删除。

docker rmi 可以删除不需要的镜像,如果有容器是基于这个镜像创建的,先删除容器。

Options:
-f, --force Force removal of the image
--no-prune Do not delete untagged parents

实例:

  1. [root@localhost ~]# docker rmi nginx
  2. Error response from daemon: conflict: unable to remove repository reference "nginx" (must force) - container eae194657981 is using its referenced image c316d5a335a5
  3. nginx
  4. 正在运行 有容器在使用中
  5. [root@localhost ~]# docker rmi centos
  6. Untagged: centos:latest
  7. Untagged: centos@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
  8. Deleted: sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6
  9. Deleted: sha256:74ddd0ec08fa43d09f32636ba91a0a3053b02cb4627c35051aff89f853606b59
  10. 删除成功

5)设置镜像标签

  1. 镜像标签,用于标记镜像。利用docker tag 命令可以对本地境像添加标签,标签就是一个别名,一个镜像可以有多个标签,但只能有一个ID。

Usage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

  1. docker tag 镜像名:原标签名 镜像名:新标签名

6)镜像的导入和导出。

  1. 导出:就是指本地docker里的镜像文件导到centos,文件。
  2. 导入:把导出的镜像文件回导到docker里。

导出:docker save

docker save [OPTIONS] IMAGE [IMAGE...]

docker save -o nginx.tar nginx:latest

实例:

  1. [root@localhost ~]# docker save -o nginx.tar nginx:latest
  2. [root@localhost ~]# ll
  3. total 142516
  4. -rw-------. 1 root root 1233 Feb 22 22:44 anaconda-ks.cfg
  5. -rw-------. 1 root root 145931776 Feb 28 19:02 nginx.tar

导入:docker load

Usage: docker load [OPTIONS]

Options:

-i, --input string Read from tar archive file, instead of STDIN

-q, --quiet Suppress the load output

  1. [root@localhost ~]# docker load -i nginx.tar
标签: docker 容器 运维

本文转载自: https://blog.csdn.net/weixin_55800462/article/details/123176273
版权归原作者 a'ゞ过去已成回忆 所有, 如有侵权,请联系我们删除。

“Docker 基础命令讲解实例(镜像)”的评论:

还没有评论