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

[经验分享] Docker实践

[复制链接]

尚未签到

发表于 2015-10-13 12:27:15 | 显示全部楼层 |阅读模式
一、Docker是什么
  docker直译为码头工人。当它成为一种技术时,做的也是码头工人的事。官网是这样描述它的:“Docker是一个开发的平台,用来为开发者和系统管理员构建、发布和运行分布式应用。”也就是说,如果把你的应用比喻为货物,那么码头工人(Docker)就会迅速的用集装箱将它们装上船。快速、简单而有效率。
  它是用Go语言写的,是程序运行的“容器”(Linux containers),实现了应用级别的隔离(沙箱)。多个容器运行时互补影响,安全而稳定。
  我喜欢它的原因就是快速部署,安全运行,不污染我的系统。
二、试用 Try it!
  官方提供一个互动的小教程,让你很容易的了解Docker的基本用法,快去试试吧!
三、安装
  官方直接支持64位Linux系统安装Docker,但如果想在32位系统中运行,有人也进行了一些尝试,比如32Ubuntu下,参考点击打开链接。
  其他系统的安装请参考官网,下面说说我在Ubuntu14.04下的安装。        

  1.将镜像加入到程序源中:
  ~$ sudo sh -c "echo deb http://mirror.yandex.ru/mirrors/docker/ docker main > /etc/apt/sources.list.d/docker.list"
  2.接着update
  $ sudo apt-get update
3.如果报错就fix掉它:
  W: GPG error: http://mirror.yandex.ru docker Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D8576A8BA88D21E9
解决此错误:
  $ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys D8576A8BA88D21E9
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.RmJ1SUpsXX --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys D8576A8BA88D21E9
gpg: requesting key A88D21E9 from hkp server keyserver.ubuntu.com
gpg: key A88D21E9: public key &quot;Docker Release Tool (releasedocker) <docker@dotcloud.com>&quot; imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
4.下载docker:
  $ sudo apt-get install lxc-docker
  静静的等待它下载完成吧。

  另外,这个命令也许会有帮助:
  
$ curl -sSL https://get.docker.com/ubuntu/ | sudo sh四、初步使用

终端中输入docker,打印出docker的命令列表:  Commands:
attach    Attach to a running container
build     Build an image from a Dockerfile
commit    Create a new image from a container's changes
cp        Copy files/folders from a container's filesystem to the host path
create    Create a new container
diff      Inspect changes on a container's filesystem
events    Get real time events from the server
exec      Run a command in a running container
export    Stream the contents of a container as a tar archive
history   Show the history of an image
images    List images
import    Create a new filesystem image from the contents of a tarball
info      Display system-wide information
inspect   Return low-level information on a container
kill      Kill a running container
load      Load an image from a tar archive
login     Register or log in to a Docker registry server
logout    Log out from a Docker registry server
logs      Fetch the logs of a container
port      Lookup the public-facing port that is NAT-ed to PRIVATE_PORT
pause     Pause all processes within a container
ps        List containers
pull      Pull an image or a repository from a Docker registry server
push      Push an image or a repository to a Docker registry server
restart   Restart a running container
rm        Remove one or more containers
rmi       Remove one or more images
run       Run a command in a new container
save      Save an image to a tar archive
search    Search for an image on the Docker Hub
start     Start a stopped container
stop      Stop a running container
tag       Tag an image into a repository
top       Lookup the running processes of a container
unpause   Unpause a paused container
version   Show the Docker version information
wait      Block until a container stops, then print its exit code
接下来就可以尝试使用这些命令了,不过在进行下一步之前,我们要先了解几个概念。

五、重要概念
  1.image 镜像

  镜像就是一个只读的模板。比如,一个镜像可以包含一个完整的Ubuntu系统,并且安装了apache。
  镜像可以用来创建Docker容器。

  其他人制作好镜像,我们可以拿过来轻松的使用。这就是吸引我的特性。
  2.Docker container 容器
  Docker用容器来运行应用。容器是从镜像创建出来的实例(好有面向对象的感觉,类和对象),它可以被启动、开始、停止和删除。
  3.仓库
  这个好理解了,就是放镜像的文件的场所。比如最大的公开仓库是Docker Hub。
六、几个简单的实践
  1.search
  搜索仓库中是否有wordpress这个博客镜像,如下:
  $ docker search wordpress
NAME                                   DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
wordpress                              The WordPress rich content management syst...   185       [OK]
2.下载这个镜像
  $ docker pull wordpress
wordpress:latest: The image you are pulling has been verified
3.查看自己的镜像
  $ docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
linc-wiki                latest              b5a1e34b01c2        27 hours ago        689.7 MB
ubuntu                   latest              5ba9dab47459        5 days ago          188.3 MB
wordpress                latest              ecc04d6d638c        6 days ago          470 MB

  4.简单的运行
运行wordpress要进行mysql的配置,为了演示run,将ubuntu跑起来吧。

  $ docker run -it ubuntu /bin/bash
root@46ff2a695ce1:/# echo &quot;I am linc&quot;
I am linc

  
  
  至此,体验结束。后续会有更加精彩的实践等着我们,Docker,我们来了!

  

  参考:

  https://docs.docker.com/installation/ubuntulinux/
  https://bitnami.com/stack/mediawiki
  https://docs.docker.com/userguide/
  https://dockerpool.com/static/books/docker_practice

  http://zhumeng8337797.blog.163.com/blog/static/1007689142014524115743806/
  http://www.cnblogs.com/imoing/p/dockervolumes.html
  https://github.com/docker/fig/issues/88

   
版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 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-126274-1-1.html 上篇帖子: docker安装前升级内核3.10 下篇帖子: Docker-小试牛刀
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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