Ubuntu 中Docker Compose的異巧
在本教程中,我們將看到如何在 Ubuntn 16.04 上安裝 Docker Compose。 |
我們需要安裝 Docker 來安裝 Docker Compose。首先為官方 Docker 倉庫新增公鑰。
$ curl -fsSL | sudo apt-key add -
接下來,新增 Docker 倉庫到 apt 源列表:
$ sudo add-apt-repository "deb [arch=amd64] (lsb_release -cs) stable"
更新包資料庫,並使用 apt 安裝 Docker
$ sudo apt-get update $ sudo apt install docker-ce
在安裝程式結束後,Docker 守護程式應該已經啟動並設為開機自動啟動。我們可以透過下面的 來檢視它的狀態:
$ 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 了。透過執行以下命令下載當前版本。
# curl -L `uname -s`-`uname -m` > /usr/local/bin/docker-compose
為二進位制檔案新增執行許可權:
# chmod +x /usr/local/bin/docker-compose
檢查 Docker Compose 版本:
$ docker-compose -v
輸出應該如下:
docker-compose version 1.14.0, build c7bdf9e
Docker Hub 包含了一個用於演示的 Hello World 映象,可以用來說明使用 Docker Compose 來執行一個容器所需的配置。
建立並開啟一個目錄:
$ mkdir hello-world $ cd hello-world
建立一個新的 YAML 檔案:
$ $EDITOR docker-compose.yml
在檔案中貼上如下內容:
unixmen-compose-test: image: hello-world
注意: 第一行是容器名稱的一部分。
儲存並退出。
接下來,在 hello-world 目錄執行以下命令:
$ 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 | unixmen-compose-test_1 | unixmen-compose-test_1 | For more examples and ideas, visit: unixmen-compose-test_1 | unixmen-compose-test_1 | helloworld_unixmen-compose-test_1 exited with code 0 Docker
容器只能在命令(LCTT 譯註:此處應為容器中的命令)還處於活動狀態時執行,因此當測試完成執行時,容器將停止執行。
本文是關於在 Ubuntu 16.04 中安裝 Docker Compose 的教程。我們還看到了如何透過一個 YAML 格式的 Compose 檔案構建一個簡單的專案。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69901823/viewspace-2989611/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Ubuntu 安裝最新 docker docker-composeUbuntuDocker
- Ubuntu安裝Docker及Docker-composeUbuntuDocker
- Ubuntu Server 24.04 LTS 安裝 Docker 與 Docker ComposeUbuntuServerDocker
- 如何使用RubyMine中的Docker / Docker Compose?Docker
- Docker compose的使用Docker
- docker composeDocker
- Docker 和 Docker ComposeDocker
- Docker:Docker Compose 詳解Docker
- docker compose 用法Docker
- Docker Compose fileDocker
- Docker Compose 案例Docker
- docker compose 指令Docker
- 在Ubuntu中安裝Docker和docker的使用UbuntuDocker
- Ubuntu中安裝DockerUbuntuDocker
- Docker-compose networks 的例子Docker
- 自用 docker-composeDocker
- Docker學習—ComposeDocker
- Docker Compose簡介Docker
- docker-compose教程Docker
- Docker Compose 安裝Docker
- Docker Compose部署GitLabDockerGitlab
- docker compose 語法Docker
- Docker 容器編排利器 Docker ComposeDocker
- docker-compose vs docker-stackDocker
- Docker(四):Docker 三劍客之 Docker ComposeDocker
- docker-compose部署ELKDocker
- 46_docker-compose_nginxDockerNginx
- docker-compose 安裝Docker
- Docker-compose實戰Docker
- Docker-Compose基礎Docker
- docker-compose安裝Docker
- Docker Compose 快速入門Docker
- Docker-Compose學習Docker
- docker-compose 編排Docker
- Docker Compose 安裝 RabbitMQDockerMQ
- Docker compose 編排LNPDocker
- IDEA的Docker外掛實戰(Docker-compose篇)IdeaDocker
- Docker & ASP.NET Core (5):Docker ComposeDockerASP.NET