1.从docker hub中下载ubuntu14.04的镜像

root@ubuntu02:~# docker pull ubuntu:14.04
14.04: Pulling from library/ubuntu
050aa9ae81a9: Pull complete
1eb2c989bc04: Pull complete
f5e83780ccda: Pull complete
2dec31d7323c: Pull complete
286f32949bdc: Pull complete
Digest: sha256:084989eb923bd86dbf7e706d464cf3587274a826b484f75b69468c19f8ae354c
Status: Downloaded newer image for ubuntu:14.04
root@ubuntu02:~#

2.查看所下载镜像的信息, IMAGE ID是镜像唯一标记信息

root@ubuntu02:~# docker images ubuntu
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 14.04 67759a80360c 4 days ago 221MB

3.使用ubuntu14.04镜像创建一个容器,并运行bash应用

root@ubuntu02:~# docker run -it ubuntu:14.04 bash

root@f98509a7db40:/# ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.031 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.080 ms
^C
--- localhost ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.031/0.055/0.080/0.025 ms

root@f98509a7db40:/# df -h
Filesystem Size Used Avail Use% Mounted on
overlay 49G 1.9G 45G 5% /
tmpfs 64M 0 64M 0% /dev
tmpfs 240M 0 240M 0% /sys/fs/cgroup
/dev/sda2 49G 1.9G 45G 5% /etc/hosts
shm 64M 0 64M 0% /dev/shm
tmpfs 240M 0 240M 0% /proc/scsi
tmpfs 240M 0 240M 0% /sys/firmware

root@f98509a7db40:/# cat /etc/issue
Ubuntu 14.04.5 LTS \n \l

root@f98509a7db40:/# uname -r
4.4.0-31-generic

root@f98509a7db40:/# uname -a
Linux f98509a7db40 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
root@f98509a7db40:/#

4.tag一个镜像标签

root@ubuntu02:~# docker images ubuntu
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 14.04 67759a80360c 4 days ago 221MB

root@ubuntu02:~# docker tag ubuntu:14.04 ubuntu:14.04_Nginx

root@ubuntu02:~# docker images ubuntu
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 14.04 67759a80360c 4 days ago 221MB
ubuntu 14.04_Nginx 67759a80360c 4 days ago 221MB
root@ubuntu02:~#

可以发现ubuntu 14.04 和 ubuntu 14.04_Nginx 的 IMAGE ID是一样的,他们其实是指向同一个镜像,只是别名不同而已,起到一个类似链接的作用。

5.查看镜像的详细信息

root@ubuntu02:~# docker inspect ubuntu:14.04_Nginx
[
{
"Id": "sha256:67759a80360cbaef77ec1eee8aa0590f07ba04c26ef496efbc90391f217fd9d6",
"RepoTags": [
"ubuntu:14.04",
"ubuntu:14.04_Nginx"
],
"RepoDigests": [br/>"ubuntu@sha256:084989eb923bd86dbf7e706d464cf3587274a826b484f75b69468c19f8ae354c"
],
"Parent": "",
"Comment": "",
"Created": "2017-12-14T20:59:24.060013808Z",
"Container": "189ade29d9914a5b6f6c7696f87dcc18fbff2ccd42ce2d49c3441305a384ea05",
"ContainerConfig": {
"Hostname": "189ade29d991",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"/bin/bash\"]"
],
"ArgsEscaped": true,
"Image": "sha256:e87bb0972fca147c25f12082262a42f668908fa1115f1ccdbbc4524274bae3a7",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"DockerVersion": "17.06.2-ce",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"ArgsEscaped": true,
"Image": "sha256:e87bb0972fca147c25f12082262a42f668908fa1115f1ccdbbc4524274bae3a7",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"Architecture": "amd64",
"Os": "linux",
"Size": 221419148,
"VirtualSize": 221419148,
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/2ea7aa47af358f7d473a8fd9b37ed3bcc0bc91e1fda6a0ebb6fce8f7f79f0503/diff:/var/lib/docker/overlay2/4365847b0dd1af79a801be3c15134b2afdcf2902f27e529919cb335d97126d93/diff:/var/lib/docker/overlay2/2b6a970a00777f76824a1cc63b004122267019f44f8b0ba9f938b45c268b584a/diff:/var/lib/docker/overlay2/fe06b216c932673142b47fd0d3b1e1e2d9704760835064c5bd8a9112474cfb35/diff",
"MergedDir": "/var/lib/docker/overlay2/242b131515a5dfdf65fc1b8e2705db39cc7538647bb093646215398a991c449e/merged",
"UpperDir": "/var/lib/docker/overlay2/242b131515a5dfdf65fc1b8e2705db39cc7538647bb093646215398a991c449e/diff",
"WorkDir": "/var/lib/docker/overlay2/242b131515a5dfdf65fc1b8e2705db39cc7538647bb093646215398a991c449e/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:3c55a4645443b4d71f9eb1827b1008c9fa149364bb0bbfe6c73d82a4070a06a7",
"sha256:7311554c0ad2d7b97b982edaa8a38b4afba10f740c4becf33dd56d8084d22a41",
"sha256:a444e38e200bdb629c41a8019a8bfeb32c88a1f1bcb9198202d790d7942bb7fd",
"sha256:6103e9cd782d8d7742b9509f11d70f93a7a7be33e3a59817761bd6deb6528e1e",
"sha256:37095707a14c9589186a23453defe47f134b932bad350483625910733f7ef9df"
]
},
"Metadata": {
"LastTagTime": "2017-12-20T00:36:33.496267325+08:00"
}
}
]
root@ubuntu02:~#

返回一个JSON格式的消息

如果只需某一项信息,可以如下指定

root@ubuntu02:~# docker inspect ubuntu:14.04_Nginx -f {{".DockerVersion"}}
17.06.2-ce
root@ubuntu02:~#

6.搜索指定条件的镜像

root@ubuntu02:~# docker search --filter=is-automated=true --filter=stars=4 nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1200 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 485 [OK]
jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as p… 272 [OK]
webdevops/php-nginx Nginx with PHP-FPM 92 [OK]
bitnami/nginx Bitnami nginx Docker Image 42 [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 20 [OK]
tobi312/rpi-nginx NGINX on Raspberry Pi / armhf 13 [OK]
wodby/drupal-nginx Nginx for Drupal 9 [OK]
blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 8 [OK]
webdevops/nginx Nginx container 8 [OK]
1science/nginx Nginx Docker images that include Consul Temp… 4 [OK]
root@ubuntu02:~#

7.使用标签删除镜像
root@ubuntu02:~# docker images ubuntu
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 14.04 67759a80360c 4 days ago 221MB
ubuntu 14.04_Nginx 67759a80360c 4 days ago 221MB
root@ubuntu02:~# docker rmi ubuntu:14.04_Nginx
Untagged: ubuntu:14.04_Nginx
root@ubuntu02:~# docker images ubuntu
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 14.04 67759a80360c 4 days ago 221MBbr/>root@ubuntu02:~#
上面只是删除镜像标签

root@ubuntu02:~# docker images ubuntu
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 14.04 67759a80360c 4 days ago 221MB

root@ubuntu02:~# docker rmi ubuntu:14.04
Error response from daemon: conflict: unable to remove repository reference "ubuntu:14.04" (must force) - container f98509a7db40 is using its referenced image 67759a80360c

无法删除镜像,因为,已经使用它创建容器

查看本机上存在的所用容器

root@ubuntu02:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f98509a7db40 ubuntu:14.04 "bash" 18 minutes ago Exited (0) 14 minutes ago thirsty_mclean
0ab2ed6ba9f7 centos "/bin/bash" 24 hours ago Exited (127) 24 hours ago keen_engelbart
root@ubuntu02:~#

可以使用-f 来强制删除一个容器,但不建议这么做

root@ubuntu02:~# docker rmi -f ubuntu:14.04
Untagged: ubuntu:14.04
Untagged: ubuntu@sha256:084989eb923bd86dbf7e706d464cf3587274a826b484f75b69468c19f8ae354c
Deleted: sha256:67759a80360cbaef77ec1eee8aa0590f07ba04c26ef496efbc90391f217fd9d6
root@ubuntu02:~#

上面ubuntu:14.04的镜像已删除,但它的容器居然还存在
root@ubuntu02:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f98509a7db40 67759a80360c "bash" 22 minutes ago Exited (0) 18 minutes ago thirsty_mclean
0ab2ed6ba9f7 centos "/bin/bash" 25 hours ago Exited (127) 24 hours ago keen_engelbart

root@ubuntu02:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 3fa822599e10 2 weeks ago 204MB

8.可以先删除容器,再删除镜像
root@ubuntu02:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f98509a7db40 67759a80360c "bash" 25 minutes ago Exited (0) 22 minutes ago thirsty_mclean
0ab2ed6ba9f7 centos "/bin/bash" 25 hours ago Exited (127) 24 hours ago keen_engelbart

root@ubuntu02:~# docker rm f98509a7db40
f98509a7db40

root@ubuntu02:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0ab2ed6ba9f7 centos "/bin/bash" 25 hours ago Exited (127) 24 hours ago

9.创建镜像,主要有3种方法,基于已有的镜像的容器创建,基于本地模板导入,基于Dockerfile创建。

9.1.基于已有的镜像的容器创建

查看本地已存在的容器

root@ubuntu02:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0ab2ed6ba9f7 centos "/bin/bash" 25 hours ago Exited (127) 24 hours ago keen_engelbart

启动本地一个容器

root@ubuntu02:~# docker start 0ab2ed6ba9f7
0ab2ed6ba9f7

进入容器
root@ubuntu02:~# docker attach 0ab2ed6ba9f7
[root@0ab2ed6ba9f7 /]#

[root@0ab2ed6ba9f7 /]# df -h
Filesystem Size Used Avail Use% Mounted on
overlay 49G 1.7G 45G 4% /
tmpfs 64M 0 64M 0% /dev
tmpfs 240M 0 240M 0% /sys/fs/cgroup
/dev/sda2 49G 1.7G 45G 4% /etc/hosts
shm 64M 0 64M 0% /dev/shm
tmpfs 240M 0 240M 0% /proc/scsi
tmpfs 240M 0 240M 0% /sys/firmware

安装apache,此时容器里面的内容一发生变化

[root@0ab2ed6ba9f7 /]# yum install httpd -y
Loaded plugins: fastestmirror, ovl
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 156 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 145 kB 00:00:00
(3/4): updates/7/x86_64/primary_db | 4.5 MB 00:00:03
(4/4): base/7/x86_64/primary_db | 5.7 MB 00:00:04
Determining fastest mirrors

  • base: mirrors.shuosc.org
  • extras: mirror.lzu.edu.cn
  • updates: mirrors.shuosc.org
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.x86_64 0:2.4.6-67.el7.centos.6 will be installed
    --> Processing Dependency: httpd-tools = 2.4.6-67.el7.centos.6 for package: httpd-2.4.6-67.el7.centos.6.x86_64
    --> Processing Dependency: system-logos >= 7.92.1-1 for package: httpd-2.4.6-67.el7.centos.6.x86_64
    --> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-67.el7.centos.6.x86_64
    --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-67.el7.centos.6.x86_64
    --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-67.el7.centos.6.x86_64
    --> Running transaction check
    ---> Package apr.x86_64 0:1.4.8-3.el7_4.1 will be installed
    ---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
    ---> Package centos-logos.noarch 0:70.0.6-3.el7.centos will be installed
    ---> Package httpd-tools.x86_64 0:2.4.6-67.el7.centos.6 will be installed
    ---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
    --> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================
Package Arch Version Repository Size
========================================================================================================================================================Installing:
httpd x86_64 2.4.6-67.el7.centos.6 updates 2.7 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7_4.1 updates 103 k
apr-util x86_64 1.5.2-6.el7 base 92 k
centos-logos noarch 70.0.6-3.el7.centos base 21 M
httpd-tools x86_64 2.4.6-67.el7.centos.6 updates 88 k
mailcap noarch 2.1.41-2.el7 base 31 k

Transaction Summary

========================================================================================================================================================
Install 1 Package (+5 Dependent packages)

Total download size: 24 M
Installed size: 32 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/apr-util-1.5.2-6.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY0 B --:--:-- ETA
Public key for apr-util-1.5.2-6.el7.x86_64.rpm is not installed
(1/6): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:00
Public key for httpd-tools-2.4.6-67.el7.centos.6.x86_64.rpm is not installed
(2/6): httpd-tools-2.4.6-67.el7.centos.6.x86_64.rpm | 88 kB 00:00:00
(3/6): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
(4/6): httpd-2.4.6-67.el7.centos.6.x86_64.rpm | 2.7 MB 00:00:02
(5/6): apr-1.4.8-3.el7_4.1.x86_64.rpm | 103 kB 00:00:03
(6/6): centos-logos-70.0.6-3.el7.centos.noarch.rpm | 21 MB 00:00:08

Total 2.7 MB/s | 24 MB 00:00:08
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) "
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-4.1708.el7.centos.x86_64 (@CentOS)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7_4.1.x86_64 1/6
Installing : apr-util-1.5.2-6.el7.x86_64 2/6
Installing : httpd-tools-2.4.6-67.el7.centos.6.x86_64 3/6
Installing : centos-logos-70.0.6-3.el7.centos.noarch 4/6
Installing : mailcap-2.1.41-2.el7.noarch 5/6
Installing : httpd-2.4.6-67.el7.centos.6.x86_64 6/6
Verifying : mailcap-2.1.41-2.el7.noarch 1/6
Verifying : httpd-2.4.6-67.el7.centos.6.x86_64 2/6
Verifying : apr-util-1.5.2-6.el7.x86_64 3/6
Verifying : httpd-tools-2.4.6-67.el7.centos.6.x86_64 4/6
Verifying : apr-1.4.8-3.el7_4.1.x86_64 5/6
Verifying : centos-logos-70.0.6-3.el7.centos.noarch 6/6

Installed:
httpd.x86_64 0:2.4.6-67.el7.centos.6

Dependency Installed:
apr.x86_64 0:1.4.8-3.el7_4.1 apr-util.x86_64 0:1.5.2-6.el7 centos-logos.noarch 0:70.0.6-3.el7.centos httpd-tools.x86_64 0:2.4.6-67.el7.centos.6
mailcap.noarch 0:2.1.41-2.el7

Complete!
[root@0ab2ed6ba9f7 /]#

9.1.1保存提交生成一个新的镜像
root@ubuntu02:~# docker commit -m "create a new apache containter" -a "Docker Apache" 0ab2ed6ba9f7 Apache:2.4.6

invalid reference format: repository name must be lowercase
镜像名称必须是小写

root@ubuntu02:~# docker commit -m "create a new apache containter" -a "Docker Apache" 0ab2ed6ba9f7 apache:2.4.6

sha256:340d08d146e23589b48a144d11e23527dbe108964e26b8f167cfe392f33f83f5

root@ubuntu02:~#

查看结果
root@ubuntu02:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
apache 2.4.6 340d08d146e2 About a minute ago 322MB
centos latest 3fa822599e10 2 weeks ago 204MB
root@ubuntu02:~#

9.1.2 存出镜像到本地

root@ubuntu02:~# docker save -o centos_apache_2.4.6.tar apache:2.4.6
root@ubuntu02:~# ls -ltr centos_apache_2.4.6.tar
-rw------- 1 root root 331751936 Dec 20 01:13 centos_apache_2.4.6.tar
root@ubuntu02:~#

此时,你可以copy这个centos_apache_2.4.6.tar 镜像文件分享给别人了

9.1.3、载入镜像
root@ubuntu02:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
apache 2.4.6 340d08d146e2 8 minutes ago 322MB
centos latest 3fa822599e10 2 weeks ago 204MB
root@ubuntu02:~# docker rmi apache:2.4.6
Untagged: apache:2.4.6
Deleted: sha256:340d08d146e23589b48a144d11e23527dbe108964e26b8f167cfe392f33f83f5
Deleted: sha256:77fd972fc1f4f9beaca7e7a0c35cb2b2f2c1062ea9e92af4df093184ea5b42f9
root@ubuntu02:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 3fa822599e10 2 weeks ago 204MB
root@ubuntu02:~# docker load --input centos_apache_2.4.6.tar
44712c061e8a: Loading layer [==================================================>] 119.7MB/119.7MB
Loaded image: apache:2.4.6
root@ubuntu02:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
apache 2.4.6 340d08d146e2 9 minutes ago 322MB
centos latest 3fa822599e10 2 weeks ago 204MB
root@ubuntu02:~#

下面两个后面再更新
9.2、基于本地模板导入
其实9.1 save出来的镜像就相当于一个本地镜像模板了

我们也可以使用OpenVZ提供的模板来创建

https://download.openvz.org/template/precreated/

下载一个镜像模板

root@ubuntu02:~# wget https://download.openvz.org/template/precreated/suse-13.2-x86_64.tar.gz
--2017-12-20 23:59:24-- https://download.openvz.org/template/precreated/suse-13.2-x86_64.tar.gz
Resolving download.openvz.org (download.openvz.org)... 195.214.232.142
Connecting to download.openvz.org (download.openvz.org)|195.214.232.142|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 258435717 (246M) [application/x-gzip]
Saving to: ‘suse-13.2-x86_64.tar.gz’

9% [=====> ] 24,109,056 60.1KB/s eta 76m 38s

检查下载的模板

root@ubuntu02:~# ls -lt suse-13.2-x86_64.tar.gz
-rw-r--r-- 1 root root 258435717 Nov 27 2016 suse-13.2-x86_64.tar.gz
root@ubuntu02:~#

载入镜像模板,先检查原有的镜像

root@ubuntu02:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hub.docker.com/dockerhadoop123/centos-apahe latest afb75bc2d778 47 hours ago 322MB
hub.docker.com:443/dockerhadoop123/centos-apahe latest afb75bc2d778 47 hours ago 322MB
dockerhadoop123/centos-apahe latest afb75bc2d778 47 hours ago 322MB
centos-apahe latest afb75bc2d778 47 hours ago 322MB
dockerhadoop123:5000/centos-apahe latest afb75bc2d778 47 hours ago 322MB
dockerhadoop123/centos latest 3fa822599e10 3 weeks ago 204MB
centos latest 3fa822599e10 3 weeks ago 204MB

开始载入

root@ubuntu02:~# cat suse-13.2-x86_64.tar.gz | docker import - suse:13.2
sha256:0fe731462d6b50a3f0d608f6c5d9ad1142205c6492799086e8f55ff79a20fa69

检查载入镜像结果

root@ubuntu02:~# docker images | grep suse
suse 13.2 0fe731462d6b 27 seconds ago 767MB

查看镜像详细信息

root@ubuntu02:~# docker inspect suse:13.2
[
{
"Id": "sha256:0fe731462d6b50a3f0d608f6c5d9ad1142205c6492799086e8f55ff79a20fa69",
"RepoTags": [
"suse:13.2"
],
"RepoDigests": [],
"Parent": "",
"Comment": "Imported from -",
"Created": "2017-12-22T15:51:50.442672491Z",
"Container": "",
"ContainerConfig": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": null,
"Cmd": null,
"Image": "",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"DockerVersion": "17.11.0-ce",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": null,
"Cmd": null,
"Image": "",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"Architecture": "amd64",
"Os": "linux",
"Size": 767110085,
"VirtualSize": 767110085,
"GraphDriver": {
"Data": {
"MergedDir": "/var/lib/docker/overlay2/5c3dee287b79da46f8ff7085aeb2ffc48e89fc94dee4ef4deed52f4c85f7d2c2/merged",
"UpperDir": "/var/lib/docker/overlay2/5c3dee287b79da46f8ff7085aeb2ffc48e89fc94dee4ef4deed52f4c85f7d2c2/diff",
"WorkDir": "/var/lib/docker/overlay2/5c3dee287b79da46f8ff7085aeb2ffc48e89fc94dee4ef4deed52f4c85f7d2c2/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:d62c2e5e3118d9fbb162be59a0d63bf91615d978c8cbaf57e98d97afa2ab1f04"
]
},
"Metadata": {
"LastTagTime": "2017-12-22T23:51:50.449093292+08:00"
}
}
]

root@ubuntu02:~# docker run -it suse:13.2 bash
1bbeb9c5e992:/ # df -h
Filesystem Size Used Avail Use% Mounted on
overlay 49G 3.7G 43G 8% /
tmpfs 64M 0 64M 0% /dev
tmpfs 240M 0 240M 0% /sys/fs/cgroup
/dev/sda2 49G 3.7G 43G 8% /etc/hosts
shm 64M 0 64M 0% /dev/shm
tmpfs 240M 0 240M 0% /proc/scsi
tmpfs 240M 0 240M 0% /sys/firmware

1bbeb9c5e992:/ # cat /etc/issue
Welcome to openSUSE 13.2 "Harlequin" - Kernel \r (\l).

1bbeb9c5e992:/ # uname -r
4.4.0-31-generic

查看IP

1bbeb9c5e992:/ # ip ad
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
4: eth0@if5: mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.2/16 scope global eth0
valid_lft forever preferred_lft forever

查看网关

1bbeb9c5e992:/ # netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.17.0.1 0.0.0.0 UG 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
1bbeb9c5e992:/ #

9.3 、基于Dockerfile创建,后面会更新。

9.4 上传镜像到hub.docker.com
需要现在hub.docker.com上创建一个账号,然后才能使用这个账号上传
root@ubuntu02:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PO RTS NAMES
b661717d9d7d dockerhadoop123/dockerimagestest/suse:13.2 "bash" 11 minutes ago Exited (127) 10 minutes ago eager_almeida
1bbeb9c5e992 suse:13.2 "bash" 19 minutes ago Exited (0) 17 minutes ago zealous_almeida
611d7931df4d centos "bash" 2 days ago Exited (0) 2 days ago priceless_carson
root@ubuntu02:~# docker commit 1bbeb9c5e992 dockerhadoop123/suse
sha256:d3e70739d1b11a81b1560eedb41f71e4a59f25bfb3d4e0945d7ba04ba809c5dc

需要先登录

root@ubuntu02:~# 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 (dockerhadoop123): dockerhadoop123
Password:
Login Succeeded

再上传

root@ubuntu02:~# docker push dockerhadoop123/suse
The push refers to repository [docker.io/dockerhadoop123/suse]
c44f74b8f66c: Pushed
d62c2e5e3118: Pushed
latest: digest: sha256:51d7b51d3fdf4b6da5a1b753d73e3ac57059d679d0761f00ad2b82a7b9624bf4 size: 737
root@ubuntu02:~#

上传成功
现在登录hub.docker.com去查看了,如下图

docker镜像的使用方法_第1张图片