1.启动Docker
[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: https://docs.docker.com
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
2.镜像=>仓库
镜像存放在仓库,下载镜像,创建生成容器。
容器(对象,动态)
1)镜像信息查看
docker images 可以列出本地仓库存储的镜像。
实例:
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest c316d5a335a5 4 weeks ago 142MB
字段解释:
PEPOSITORY ---表示镜像的仓库源
TAG ---镜像的标签
IMAGE ID ---镜像ID
CREATED --- 镜像创建时间
SIZE ---镜像大小
docker images [选项] [镜像名字][:TAG]
-a 显示仓库所有镜像
-f 按条件检索镜像
-q 显示镜像ID
Flag shorthand -h has been deprecated, please use --help
Usage: 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
2)获取镜像
docker pull [选项][name][:TAG@DIGEST]
镜像名字 + 版本 --不加版本默认最新版本
实例:
获取centos最新 centos:latest [root@localhost ~]# docker pull centos:latest latest: Pulling from library/centos a1d0c7532777: Pull complete Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177 Status: Downloaded newer image for centos:latest
docker images 查看新下载镜像
指定镜像名字 [root@localhost ~]# docker images centos REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 5d0da3dc9764 5 months ago 231MB
3)镜像查找
docker search [OPTIONS] TERM 查找仓库中
-f 过滤查找需要镜像
实例:
[root@localhost ~]# docker search ubuntu NAME DEscriptION STARS OFFICIAL AUTOMATED ubuntu/nginx Nginx, a high-performance reverse proxy & we… 33 ubuntu/mysql MySQL open source fast, stable, multi-thread… 24 ubuntu/apache2 Apache, a secure & extensible open-source HT… 23 ubuntu/prometheus Prometheus is a systems and service monitori… 23 kasmweb/ubuntu-bionic-desktop Ubuntu productivity desktop for Kasm Workspa… 18 ubuntu/postgres PostgreSQL is an open source object-relation… 13 ubuntu/squid Squid is a caching proxy for the Web. Long-t… 12 ubuntu/bind9 BIND 9 is a very flexible, full-featured DNS… 12 ubuntu/redis Redis, an open source key-value store. Long-… 8 ubuntu/prometheus-alertmanager alertmanager handles client alerts from Prom… 5 ubuntu/grafana Grafana, a feature rich metrics dashboard & … 5 ubuntu/telegraf Telegraf collects, processes, aggregates & w… 3 circleci/ubuntu-server This image is for internal use 3 ubuntu/memcached Memcached, in-memory keyvalue store for smal… 3 ubuntu/cortex Cortex provides storage for Prometheus. Long… 2 ubuntu/cassandra Cassandra, an open source NoSQL distributed … 1 ubuntu Ubuntu is a Debian-based Linux operating sys… 0 [OK] ubuntu-upstart DEPRECATED, as is Upstart (find other proces… 0 [OK] neurodebian NeuroDebian provides neuroscience research s… 0 [OK] open-liberty Open Liberty multi-architecture images based… 0 [OK] ubuntu-debootstrap DEPRECATED; use "ubuntu" instead 0 [OK] bitnami/ubuntu-base-buildpack Ubuntu base compilation image 0 [OK] websphere-liberty WebSphere Liberty multi-architecture images … 0 [OK] snyk/ubuntu A base ubuntu image for all broker clients t… 0 rancher/ubuntuconsole 0
4)镜像删除。
docker rmi 可以删除不需要的镜像,如果有容器是基于这个镜像创建的,先删除容器。
Options:
-f, --force Force removal of the image
--no-prune Do not delete untagged parents
实例:
[root@localhost ~]# docker rmi nginx Error response from daemon: conflict: unable to remove repository reference "nginx" (must force) - container eae194657981 is using its referenced image c316d5a335a5 nginx 正在运行 有容器在使用中 [root@localhost ~]# docker rmi centos Untagged: centos:latest Untagged: centos@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177 Deleted: sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6 Deleted: sha256:74ddd0ec08fa43d09f32636ba91a0a3053b02cb4627c35051aff89f853606b59 删除成功
5)设置镜像标签
- 镜像标签,用于标记镜像。利用docker tag 命令可以对本地境像添加标签,标签就是一个别名,一个镜像可以有多个标签,但只能有一个ID。
Usage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
docker tag 镜像名:原标签名 镜像名:新标签名
6)镜像的导入和导出。
导出:就是指本地docker里的镜像文件导到centos,文件。
导入:把导出的镜像文件回导到docker里。
导出:docker save
docker save [OPTIONS] IMAGE [IMAGE...]
docker save -o nginx.tar nginx:latest
实例:
[root@localhost ~]# docker save -o nginx.tar nginx:latest [root@localhost ~]# ll total 142516 -rw-------. 1 root root 1233 Feb 22 22:44 anaconda-ks.cfg -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
[root@localhost ~]# docker load -i nginx.tar



