codecamp

Docker 初步体验


一、初步使用

终端中输入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 "I am linc"  
  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

Docker 安装
Docker 搭建hg-server
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }