Docker基本命令与使用 —— Docker镜像与仓库(二)

一.查看和删除镜像

1.Docker Image 镜像

  • 容器的基石
  • 层叠的只读文件系统
  • 联合加载(union mount) (存储位置 /var/lib/docker)
docker info

2.列出镜像

docker images [OPTIONS] [REPOSITORY]

-a,--all=false 默认并不显示中间层镜像

-f,--filter=[] 过滤条件
-no-trunc=false 不以截断的形式显示数据(镜像的唯一Id)
-q,--quiet=false 只显示镜像的唯一Id
Repository + Tag 完整的镜像名,对应一个唯一的镜像Id
 

3.查看镜像

docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...]

4.删除镜像

docker rmi [OPTIONS] IMAGE [IMAGE...]

-f,--force=false Force removal of the image

--no-prune=false Do not delete untagged parents
 

二.获取和推送镜像

1.查找镜像

Docker Hub: https//registry.hub.docker.com
docker search [OPTIONS] TERM

--automated=false Only show automated builds

--no-trun=false Don't truncate output
-s,--start=0 Only displays with at least x starts
 

2.拉取镜像

docker pull [OPTIONS] NAME [:TAG]

-a.--all-tags=false Download all tagged images in the repository

 

3.使用镜像代理

使用 --registry-mirror 选项
1.修改: /etc/default/docker
2.添加: DOCKER_OPTS = "--registry-mirror=http://MIRROR-ADDR"
(https://www.daocloud.io)
 

4.推送镜像

docker push NAME[:TAG]

输入DockerHub上的用户名,密码,注册邮箱

 

三.构建镜像

1.通过容器来构建镜像

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

-a, --authof="" Author. eg. "John Hannibal Smith Hannibal@a-team.com"

-m,--message="" Commit message
-p,--pause=true Pause container during commit 暂停正在执行的容器
eg. docker commit -a 'haidong' -m 'nginx' 容器id/name(需要提交的容器) dockerHub上的名字+容器名字(镜像名字)
 

2.通过Dockerfile文件构建

docker build [OPTIONS] PATH | URL | - (path,url指dockerfile构建的文件路径)

--force-rm=false

--no-cache=false
--pull=false
-q,--quiet=false
--rm=true
-t,--tag="" 制定构建出镜像的名字
 
  1. 创建Dockerfile
#First Dockerfile
FROM ubuntu:14.04
MAINTAINER dormancypress "dormancypress@outlook.com"
RUN apt-get update
RUN apt-get install -y nginx
EXPOSE 80
  • 使用 docker build 命令
docker build -t='dormancypress/df_test1' .(.表示当前目录)
原文地址:https://www.cnblogs.com/Hai--D/p/6938241.html