Docker 初步體驗(yàn)

2018-09-26 16:35 更新

一、初步使用

終端中輸入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  

接下來(lái)就可以嘗試使用這些命令了,不過(guò)在進(jìn)行下一步之前,我們要先了解幾個(gè)概念。

二、重要概念

1.image 鏡像

鏡像就是一個(gè)只讀的模板。比如,一個(gè)鏡像可以包含一個(gè)完整的Ubuntu系統(tǒng),并且安裝了apache。

鏡像可以用來(lái)創(chuàng)建Docker容器。

其他人制作好鏡像,我們可以拿過(guò)來(lái)輕松的使用。這就是吸引我的特性。

2.Docker container 容器

Docker用容器來(lái)運(yùn)行應(yīng)用。容器是從鏡像創(chuàng)建出來(lái)的實(shí)例(好有面向?qū)ο蟮母杏X(jué),類(lèi)和對(duì)象),它可以被啟動(dòng)、開(kāi)始、停止和刪除。

3.倉(cāng)庫(kù)

這個(gè)好理解了,就是放鏡像的文件的場(chǎng)所。比如最大的公開(kāi)倉(cāng)庫(kù)是Docker Hub。

三、幾個(gè)簡(jiǎn)單的實(shí)踐

1.search

搜索倉(cāng)庫(kù)中是否有wordpress這個(gè)博客鏡像,如下:

  $ docker search wordpress  
  NAME                                   DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED  
  wordpress                              The WordPress rich content management syst...   185       [OK]   

2.下載這個(gè)鏡像

  $ 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.簡(jiǎn)單的運(yùn)行
運(yùn)行wordpress要進(jìn)行mysql的配置,為了演示run,將ubuntu跑起來(lái)吧。

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

至此,體驗(yàn)結(jié)束。后續(xù)會(huì)有更加精彩的實(shí)踐等著我們,Docker,我們來(lái)了!

參考:

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

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)