设为首页 收藏本站
查看: 1718|回复: 0

[经验分享] 开始docker

[复制链接]

尚未签到

发表于 2017-12-5 23:51:11 | 显示全部楼层 |阅读模式
安装





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命令有以下三个部分:

DSC0000.png

DSC0001.png






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 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、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-420984-1-1.html 上篇帖子: 管理 Machine 下篇帖子: Docker的容器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表