1. 程式人生 > >Docker 入門實戰一(瞭解docker和安裝)

Docker 入門實戰一(瞭解docker和安裝)

什麼是Docker?

Docker 是一個開源的應用容器引擎,用Go語言並遵從Apache2.0協議開源。一次封裝到處使用。

Docker的優點:

  1. 持續部署與測試(統一環境)
  2. 可移植性
  3. 環境標準化和版本控制(docker提供tag和version來控制版本)
  4. 隔離性(容器與容器之間相互獨立)
  5. 安全性

Docker 分2大版本,CE(社群版)和 EE(企業版)

Docker quick start

前提:linux環境 centos7.0  沒有安裝過docker

先安裝映象倉庫

1 安裝所需的軟體包yum-utils 提供了 yum-config-manager

 實用程式,並且 devicemapper 儲存驅動需要device-mapper-persistent-data 和 lvm2

 $ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

2 使用下列命令新增 stable 映象倉庫:

 $ sudo yum-config-manager \
     --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

安裝Docker-ce

1 安裝最新版本的 Docker CE

 $ sudo yum install docker-ce

2 啟動docker 

 $ sudo systemctl start docker

3 設定後臺預設啟動docker

 $ systemctl enable docker

 4 驗證是否正確安裝了 docker,方法是執行 hello-world 映象。

 $ sudo docker run hello-world

看到以下程式碼代表成功 Hello from Docker!

[[email protected] ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:b3a26e22bf55e4a5232b391281fc1673f18462b75cdc76aa103e6d3a2bce5e77
Status: Downloaded newer image for hello-world:latest

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.
    (amd64)
 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 ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

5 檢視docker版本

[[email protected] ~]# docker version
Client:
 Version:           18.09.0
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        4d60db4
 Built:             Wed Nov  7 00:48:22 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.0
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.4
  Git commit:       4d60db4
  Built:            Wed Nov  7 00:19:08 2018
  OS/Arch:          linux/amd64
  Experimental:     false

不會的命令可以通過docker --help 學習,

下一篇介紹docker的映象操作命令和Dockerfile

 


參考文件:

Docker的五大優勢:http://dockone.io/article/389

Docker官方快速入門文件:https://docs.docker-cn.com/engine/installation/linux/docker-ce/centos/