新聞中心
Docker Compose是一個用來定義和運行復雜應用的Docker工具。一個使用Docker容器的應用,通常由多個容器組成。使用Docker Compose不再需要使用shell腳本來啟動容器。

創(chuàng)新互聯(lián)公司是專業(yè)的石峰網(wǎng)站建設公司,石峰接單;提供網(wǎng)站制作、做網(wǎng)站,網(wǎng)頁設計,網(wǎng)站設計,建網(wǎng)站,PHP網(wǎng)站建設等專業(yè)做網(wǎng)站服務;采用PHP框架,可快速的進行石峰網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
安裝 Docker
我們需要安裝 Docker 來安裝 Docker Compose。首先為官方 Docker 倉庫添加公鑰。
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
接下來,添加 Docker 倉庫到 apt 源列表:
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
更新包數(shù)據(jù)庫,并使用 apt 安裝 Docker
$ sudo apt-get update
$ sudo apt install docker-ce
在安裝進程結束后,Docker 守護程序應該已經(jīng)啟動并設為開機自動啟動。我們可以通過下面的命令來查看它的狀態(tài):
$ sudo systemctl status docker
---------------------------------
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running)
安裝 Docker Compose
現(xiàn)在可以安裝 Docker Compose 了。通過執(zhí)行以下命令下載當前版本。
# curl -L https://github.com/docker/compose/releases/download/1.14.0/docker-compose-
`uname -s`-`uname -m` > /usr/local/bin/docker-compose
為二進制文件添加執(zhí)行權限:
# chmod +x /usr/local/bin/docker-compose
檢查 Docker Compose 版本:
$ docker-compose -v
輸出應該如下:
docker-compose version 1.14.0, build c7bdf9e
測試 Docker Compose
Docker Hub 包含了一個用于演示的 Hello World 鏡像,可以用來說明使用 Docker Compose 來運行一個容器所需的配置。
創(chuàng)建并打開一個目錄:
$ mkdir hello-world $ cd hello-world
創(chuàng)建一個新的 YAML 文件:
$ $EDITOR docker-compose.yml
在文件中粘貼如下內(nèi)容:
unixmen-compose-test:
image: hello-world
注意: 第一行是容器名稱的一部分。 保存并退出。
運行容器
接下來,在 hello-world 目錄執(zhí)行以下命令:
$ sudo docker-compose up
如果一切正常,Compose 輸出應該如下:
Pulling unixmen-compose-test (hello-world:latest)...
latest: Pulling from library/hello-world
b04784fba78d: Pull complete
Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
Status: Downloaded newer image for hello-world:latest
Creating helloworld_unixmen-compose-test_1 ...
Creating helloworld_unixmen-compose-test_1 ... done
Attaching to helloworld_unixmen-compose-test_1
unixmen-compose-test_1 |
unixmen-compose-test_1 | Hello from Docker!
unixmen-compose-test_1 | This message shows that your installation appears to be working correctly.
unixmen-compose-test_1 |
unixmen-compose-test_1 | To generate this message, Docker took the following steps:
unixmen-compose-test_1 | 1\. The Docker client contacted the Docker daemon.
unixmen-compose-test_1 | 2\. The Docker daemon pulled the "hello-world" image from the Docker Hub.
unixmen-compose-test_1 | 3\. The Docker daemon created a new container from that image which runs the
unixmen-compose-test_1 | executable that produces the output you are currently reading.
unixmen-compose-test_1 | 4\. The Docker daemon streamed that output to the Docker client, which sent it
unixmen-compose-test_1 | to your terminal.
unixmen-compose-test_1 |
unixmen-compose-test_1 | To try something more ambitious, you can run an Ubuntu container with:
unixmen-compose-test_1 | $ docker run -it ubuntu bash
unixmen-compose-test_1 |
unixmen-compose-test_1 | Share images, automate workflows, and more with a free Docker ID:
unixmen-compose-test_1 | https://cloud.docker.com/
unixmen-compose-test_1 |
unixmen-compose-test_1 | For more examples and ideas, visit:
unixmen-compose-test_1 | https://docs.docker.com/engine/userguide/
unixmen-compose-test_1 |
helloworld_unixmen-compose-test_1 exited with code 0 Docker
容器只能在命令(LCTT 譯注:此處應為容器中的命令)還處于活動狀態(tài)時運行,因此當測試完成運行時,容器將停止運行。
結論
本文是關于在 Ubuntu 16.04 中安裝 Docker Compose 的教程。我們還看到了如何通過一個 YAML 格式的 Compose 文件構建一個簡單的項目。
標題名稱:Ubuntu中安裝和實用DockerCompose
網(wǎng)站URL:http://www.5511xx.com/article/dpogies.html


咨詢
建站咨詢
