3.1、获取镜像
-
获取镜像
docker pull name[:TAG] #默认是从网络下载镜像,不指定tag会人下载latest标签下的镜像。
12docker search ubuntu
docker pull ubuntu
-
获取指定标签的镜像
sudo docker pull ubuntu:14.04
sudo docker pull docker.io/darksheer/ubuntu #由darksheer用户上传的镜像
-
从其他注册服务器下载镜像
sudo docker pull d1.dockerpool.com:5000/ubuntu
-
利用镜像创建一个容器,并在其中运行bash
[root@kakarott wuzb]# docker run -t -i centos /bin/bash
[root@69d1a53fc9c1 /]#
3.2、查看镜像信息
-
列出本机已有的镜像(标签、仓库、镜像ID、创建时间和大小)
[root@kakarott wuzb]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/mysql latest 5faba1a71ec4 2 weeks ago 406.9 MB
docker.io/centos latest 98d35105a391 2 weeks ago 192.5 MB
docker.io/ubuntu latest 0ef2e08ed3fa 5 weeks ago 130 MB
TAG标签标注区别不同版本:比如ubuntu仓库中有多个版本的镜像14.04、12.10等等
-
给镜像添加标签
docker tag docker.io/mysql:latest mysql:latest
-
查询镜像的详细信息(通过imageID)
docker inspect 5faba1a71ec4
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849{
"Id"
:
"sha256:5faba1a71ec40108975684d095f6bac32d6db87bc55576e09deb559fbafda213"
,
"RepoTags"
: [
"docker.io/mysql:latest"
,
"mysql:latest"
],
"RepoDigests"
: [
"docker.io/mysql@sha256:b39e58483853ecd03160f9bfdc8d3ecb0be9071fdbbe5484d6a115677b62c84e"
],
"Parent"
:
""
,
"Comment"
:
""
,
"Created"
:
"2017-03-21T21:53:32.983892123Z"
,
"Container"
:
"082cc8c766b5590b15c073e268ab85673e63b543a8e4b433c5034308e4957a1b"
,
"ContainerConfig"
: {
"Hostname"
:
"7e9ec6cde4d1"
,
"Domainname"
:
""
,
"User"
:
""
,
"AttachStdin"
:
false
,
"AttachStdout"
:
false
,
"AttachStderr"
:
false
,
"ExposedPorts"
: {
"3306/tcp"
: {}
},
"Tty"
:
false
,
"OpenStdin"
:
false
,
"StdinOnce"
:
false
,
"Env"
: [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
,
"GOSU_VERSION=1.7"
,
"MYSQL_MAJOR=5.7"
,
"MYSQL_VERSION=5.7.17-1debian8"
],
"Cmd"
: [
"/bin/sh"
,
"-c"
,
"#(nop) "
,
"CMD ["mysqld"]"
],
"ArgsEscaped"
:
true
,
"Image"
:
"sha256:9ee2ffbf430a0bf54df6a0016076b677d6ee1b5c029d458390954b72aadf4391"
,
"Volumes"
: {
"/var/lib/mysql"
: {}
},
"WorkingDir"
:
""
,
"Entrypoint"
: [
"docker-entrypoint.sh"
],
"OnBuild"
: [],
"Labels"
: {}
[root@kakarott wuzb]# docker inspect -f {{".Id"}} 5faba1a71ec4
sha256:5faba1a71ec40108975684d095f6bac32d6db87bc55576e09deb559fbafda213
注:查找固定参数
3.3、搜索镜像(唯一标识是ID,标签是为了区分版本)
-
搜索镜像(查到镜像:说明、是否官方等等信息。默认是从docker hub官网上查询出来的)
docker search python
docker search python --automated=false
3.4、删除镜像
-
通过标签来删除
docker rmi mysql
特别说明:一个镜像只有唯一一个id。当一个镜像有多个标签,通过标签删除只会删除该标签。如果镜像只有
一个标签,那么就会删除该镜像。
-
通过镜像ID来删除镜像(ID唯一,如果该镜像有依赖关系是不能删除的)
docker rmi 5faba1a71ec4
docker rmi -f 5faba1a71ec4 (强制删除,但是删了镜像但是会留存依赖)
正确的删除方式:先删除依赖,再删除镜像本身
docker rm dcb
docker rmi -f 5faba1a71ec4
3.5、创建镜像
创建镜像的方法三种:基于已有镜像来创建、基于本地模板导入、基于dockerfile创建。
-
基于已有镜像创建
docker run -t -i docker.io/centos:latest
touche test
docker commit -m "Add a new file test" -a "wuzb" 040e7af9b1f5 test -m:更改内容 -a:修改者 后面的id是容器id test是仓库名
-
基于本地模板创建
cat ubuntu-16.04-x86_64.tar.gz |docker import - ubuntu:16.04
import - 【仓库名:标签名】
3.6、存出和载入镜像
-
存出镜像
docker save -o wuzb01.tar test:latest
-
载入镜像
docker load --input wuzb.tar
这里因为个载入过了,所以报了exist
3.7、上传镜像
-
step1——找到本地镜像的ID:docker images
docker images
-
step2——登陆Hub:docker login --username=username --password=password --email=email
d
ocker login --username=wap306183118 --password=******
-
step3——tag:docker tag <imageID> <namespace>/<image name>:<version tag eg latest>
docker tag wuzb:latest wap306183118/wuzb:latest
-
step4——push镜像:docker push <namespace>/<image name>
docker push wap306183118/wuzb:latest
123456789101112131415161718192021222324252627[root@kakarott wuzb]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wap306183118/wuzb latest 65ae3ff7de66 About an hour ago
130
MB
wuzb latest 65ae3ff7de66 About an hour ago
130
MB
wzb/latest latest 65ae3ff7de66 About an hour ago
130
MB
docker.io/centos latest 98d35105a391
3
weeks ago
192.5
MB
docker.io/ubuntu latest 0ef2e08ed3fa
5
weeks ago
130
MB
[root@kakarott wuzb]# docker tag wuzb:latest wap306183118/wuzb:latest
[root@kakarott wuzb]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wuzb latest 65ae3ff7de66
47
minutes ago
130
MB
wzb/latest latest 65ae3ff7de66
47
minutes ago
130
MB
wap306183118/wuzb latest 65ae3ff7de66
47
minutes ago
130
MB
docker.io/centos latest 98d35105a391
3
weeks ago
192.5
MB
docker.io/ubuntu latest 0ef2e08ed3fa
5
weeks ago
130
MB
[root@kakarott wuzb]# docker login --username=wap306183118 --password=******
Flag --email has been deprecated, will be removed
in
1.13
.
Login Succeeded
[root@kakarott wuzb]# docker push wap306183118/wuzb:latest
The push refers to a repository [docker.io/wap306183118/wuzb]
7abbbc964853: Pushed
56827159aa8b: Pushed
440e02c3dcde: Pushed
29660d0e5bb2: Pushed
85782553e37a: Pushed
745f5be9952c: Pushing [===============> ]
39
MB/
130
MB
745f5be9952c: Preparing