zane@zane-V:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
767a0a0f0bae hello-world "/hello" 30 minutes ago Exited (0) 30 minutes ago silly_mcnulty
9e6a3cb1e18b hello-world "/hello" 33 minutes ago Exited (0) 33 minutes ago tender_kare
zane@zane-V:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker ps 仅显示当前正在运行的容器
hello-world已经退出因此不会显示
Images and Containers
Docker 引擎提供的核心技术就是启用images和containers。
比如:docker run hello-world命令有以下三个部分:
zane@zane-V:~/mydockerbuild$ docker tag d09756981eeb zane0306/docker-whale:latest
c.查看你刚刚标记过的image
zane@zane-V:~/mydockerbuild$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-whale latest d09756981eeb 37 minutes ago 275.1 MB
zane0306/docker-whale latest d09756981eeb 37 minutes ago 275.1 MB
hello-world latest c54a2cc56cbb 5 months ago 1.848 kB
docker/whalesay latest 6b362a9f73eb 19 months ago 247 MB
d.命令行登录Dcoker Hub。
zane@zane-V:~/mydockerbuild$ 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: zane0306
Password:
Login Succeeded
e.docker push 命令推送自己image到存储库
zane@zane-V:~/mydockerbuild$ docker push zane0306/docker-whale
The push refers to a repository [docker.io/zane0306/docker-whale]
9748ff4991ff: Pushed
5f70bf18a086: Mounted from docker/whalesay
d061ee1340ec: Mounted from docker/whalesay
d511ed9e12e1: Mounted from docker/whalesay
091abc5148e4: Mounted from docker/whalesay
b26122d57afa: Mounted from docker/whalesay
37ee47034d9b: Mounted from docker/whalesay
528c8710fd95: Mounted from docker/whalesay
1154ba695078: Mounted from docker/whalesay
latest: digest: sha256:62b528c43afd3a2771a167a21ce005a5ee49514109d2af870336f6880ec4eca7 size: 2614
步骤二: 从远程库中拉下image
a.从本地删除原有的image
zane@zane-V:~/mydockerbuild$ docker images;
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-whale latest d09756981eeb 49 minutes ago 275.1 MB
zane0306/docker-whale latest d09756981eeb 49 minutes ago 275.1 MB
hello-world latest c54a2cc56cbb 5 months ago 1.848 kB
docker/whalesay latest 6b362a9f73eb 19 months ago 247 MB
zane@zane-V:~/mydockerbuild$ docker images;
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest c54a2cc56cbb 5 months ago 1.848 kB
docker/whalesay latest 6b362a9f73eb 19 months ago 247 MB
b.从远程拉取,并加载image
zane@zane-V:~/mydockerbuild$ docker run zane0306/docker-whale
Unable to find image 'zane0306/docker-whale:latest' locally
latest: Pulling from zane0306/docker-whale
e190868d63f8: Already exists
909cd34c6fd7: Already exists
0b9bfabab7c1: Already exists
a3ed95caeb02: Already exists
00bf65475aba: Already exists
c57b6bcc83e3: Already exists
8978f6879e2f: Already exists
8eed3712d2cf: Already exists
c7b22951dde1: Already exists
Digest: sha256:62b528c43afd3a2771a167a21ce005a5ee49514109d2af870336f6880ec4eca7
Status: Downloaded newer image for zane0306/docker-whale:latest
_________________________________________
/ As usual, this being a 1.3.x release, I \
| haven't even compiled this kernel yet. |
| So if it works, you should be doubly |
| impressed. (Linus Torvalds, announcing |
| kernel 1.3.3 on the linux-kernel |
\ mailing list.) /
-----------------------------------------
\
\
\
## .
## ## ## ==
## ## ## ## ===
/""""""""""""""""___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\______/
zane@zane-V:~/mydockerbuild$ docker run zane0306/docker-whale
_______________________________________
/ Klingon function calls do not have \
| 'parameters' -- they have 'arguments' |
| |
\ -- and they ALWAYS WIN THEM. /
---------------------------------------
\
\
\
## .
## ## ## ==
## ## ## ## ===
/""""""""""""""""___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\______/
总结
Docker Hub 与本地image的push,pull
在Docker Hub上寻找自己感兴趣的image
image 和 contaniers
image
image 是一个文件系统+参数集合。
没有状态也不可以改变
contaniers
一个正在运行的image实例
利用Dockerfile 创建自己的image
编写Dockerfile
a.指定基础image
FROM docker/whalesay:latest
b.安装fortunes程序到image中
RUN apt-get -y update && apt-get install -y fortunes