新聞中心
Docker Compose是一個(gè)用來(lái)定義和運(yùn)行復(fù)雜應(yīng)用的Docker工具。一個(gè)使用Docker容器的應(yīng)用,通常由多個(gè)容器組成。使用Docker Compose不再需要使用shell腳本來(lái)啟動(dòng)容器。

創(chuàng)新互聯(lián)公司是專業(yè)的石峰網(wǎng)站建設(shè)公司,石峰接單;提供網(wǎng)站制作、做網(wǎng)站,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行石峰網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
安裝 Docker
我們需要安裝 Docker 來(lái)安裝 Docker Compose。首先為官方 Docker 倉(cāng)庫(kù)添加公鑰。
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
接下來(lái),添加 Docker 倉(cāng)庫(kù)到 apt 源列表:
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
更新包數(shù)據(jù)庫(kù),并使用 apt 安裝 Docker
$ sudo apt-get update
$ sudo apt install docker-ce
在安裝進(jìn)程結(jié)束后,Docker 守護(hù)程序應(yīng)該已經(jīng)啟動(dòng)并設(shè)為開(kāi)機(jī)自動(dòng)啟動(dòng)。我們可以通過(guò)下面的命令來(lái)查看它的狀態(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 了。通過(guò)執(zhí)行以下命令下載當(dāng)前版本。
# curl -L https://github.com/docker/compose/releases/download/1.14.0/docker-compose-
`uname -s`-`uname -m` > /usr/local/bin/docker-compose
為二進(jìn)制文件添加執(zhí)行權(quán)限:
# chmod +x /usr/local/bin/docker-compose
檢查 Docker Compose 版本:
$ docker-compose -v
輸出應(yīng)該如下:
docker-compose version 1.14.0, build c7bdf9e
測(cè)試 Docker Compose
Docker Hub 包含了一個(gè)用于演示的 Hello World 鏡像,可以用來(lái)說(shuō)明使用 Docker Compose 來(lái)運(yùn)行一個(gè)容器所需的配置。
創(chuàng)建并打開(kāi)一個(gè)目錄:
$ mkdir hello-world $ cd hello-world
創(chuàng)建一個(gè)新的 YAML 文件:
$ $EDITOR docker-compose.yml
在文件中粘貼如下內(nèi)容:
unixmen-compose-test:
image: hello-world
注意: 第一行是容器名稱的一部分。 保存并退出。
運(yùn)行容器
接下來(lái),在 hello-world 目錄執(zhí)行以下命令:
$ sudo docker-compose up
如果一切正常,Compose 輸出應(yīng)該如下:
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 譯注:此處應(yīng)為容器中的命令)還處于活動(dòng)狀態(tài)時(shí)運(yùn)行,因此當(dāng)測(cè)試完成運(yùn)行時(shí),容器將停止運(yùn)行。
結(jié)論
本文是關(guān)于在 Ubuntu 16.04 中安裝 Docker Compose 的教程。我們還看到了如何通過(guò)一個(gè) YAML 格式的 Compose 文件構(gòu)建一個(gè)簡(jiǎn)單的項(xiàng)目。
新聞名稱:Ubuntu中安裝和實(shí)用DockerCompose
路徑分享:http://www.dlmjj.cn/article/dpogies.html


咨詢
建站咨詢
