开始docker
安装docker 目前只支持64位系统
1.下载并安装,简直太方便了
$ curl -fsSL https://get.docker.com/ | sh
用例
1.docker run hello-world
$ docker run hello-world
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
需要创建一个用户到docker 组中。
$ sudo usermod -aG docker $(whoami)
$ sudo reboot
注意:需要reboot之后才能使用
成功运行
zane@zane-V:~$ sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker Hub account:
https://hub.docker.com
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
Docker完成hello-world做的动作
[*]Docker客户端联系Docker用例
[*]Docker用例从Docker Hub 中将“hello-world”image 拉下来。
[*]Docker 用例从“hello-world” image 创建一个新的容器。而这个image运行着产生你现在读到的信息的 可执行性文件。
[*]Docker用例再讲这些输出传送到Docker客户端,然后Docker客户端在将这些信息传送到你的屏幕
2.docker ps -a 显示系统中所有的容器
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
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 rmi -f d09756981eeb
Untagged: docker-whale:latest
Untagged: zane0306/docker-whale:latest
Untagged: zane0306/docker-whale@sha256:62b528c43afd3a2771a167a21ce005a5ee49514109d2af870336f6880ec4eca7
Deleted: sha256:d09756981eebc2a3fa7d200e57be74e89147465969aa92dcbd34b3f541a90219
Deleted: sha256:4c9a56721bad2895ec49a1683737d132f13f2ca99627c5ae3b4368f1b2583919
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
[*]c.增加CMD行
[*]CMD /usr/games/fortune -a | cowsay
[*]build image
[*]zane@zane-V:~/mydockerbuild$ docker build -t docker-whale .
[*]-t 参数给image一个标签,在之后更容易的运行它。
页:
[1]