Help us understand the problem. What is going on with this article?

最もシンプルな docker-compose.yml の hello-world

docker-compose コマンドの単純な動作確認をしたい。docker run hello-world と同じレベルの docker-composehello world が欲しい

Looking for the simplest "Hello-World" docker-compose YAML file?

TL;DR

docker-compose.yml
version: "3"
services:
  hello:
    image: hello-world:latest
usage
$ curl -O https://keinos.github.io/hello-docker-compose/docker-compose.yml
$ docker-compose up

TS;DR

あれ?もしかして docker-compose 動いてない?
でも docker-compose --version は動くのに?

CircleCI 実行時や Vagrantfile 内のスクリプトで Docker や Docker-Compose を自動インストールした際に、バージョン情報は返すものの、それ以外のコマンド・オプションが動かないことがありました。原因は、設定ミスで Docker デーモンの起動に失敗していたことでした。

そこで、CI を回す時や vagrant up 時にdocker run hello-world と同じくらい至極簡単な動作テストを docker-compose でしたかったのですが、docker-compose hello-world simple」とググっても Ubuntu ベースのサンプルしかありませんでした。

単純に docker-compose up で起動するかのテストであるため、そこまで大きなイメージは必要ありません。「それなら、普通に docker の hello-wolrd イメージを使えば良いじゃん」と聞こえてきたので、自分のググラビリティとして。

実行例
$ # 作業ディレクトリの作成
$ mkdir hello-world && cd $_
$ # ダウンロード(ソースをコピペして作成しても OK)
$ curl -O https://keinos.github.io/hello-docker-compose/docker-compose.yml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    62  100    62    0     0    227      0 --:--:-- --:--:-- --:--:--   226
$ # 確認
$ ls
docker-compose.yml
$ cat docker-compose.yml
version: "3"
services:
  hello:
    image: hello-world:latest

$ # 実行
$ docker-compose up
Creating network "core_default" with the default driver
Creating core_hello_1 ... done
Attaching to core_hello_1
hello_1  | 
hello_1  | Hello from Docker!
hello_1  | This message shows that your installation appears to be working correctly.
hello_1  | 
hello_1  | To generate this message, Docker took the following steps:
hello_1  |  1. The Docker client contacted the Docker daemon.
hello_1  |  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
hello_1  |     (amd64)
hello_1  |  3. The Docker daemon created a new container from that image which runs the
hello_1  |     executable that produces the output you are currently reading.
hello_1  |  4. The Docker daemon streamed that output to the Docker client, which sent it
hello_1  |     to your terminal.
hello_1  | 
hello_1  | To try something more ambitious, you can run an Ubuntu container with:
hello_1  |  $ docker run -it ubuntu bash
hello_1  | 
hello_1  | Share images, automate workflows, and more with a free Docker ID:
hello_1  |  https://hub.docker.com/
hello_1  | 
hello_1  | For more examples and ideas, visit:
hello_1  |  https://docs.docker.com/get-started/
hello_1  | 
core_hello_1 exited with code 0
$ # 終了結果
$ echo $?
0
動作確認済み環境
$ docker version
Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.8
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:16:31 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.8
  Git commit:       e68fc7a
  Built:            Tue Aug 21 17:16:31 2018
  OS/Arch:          linux/amd64
  Experimental:     false
$ 
$ docker-compose version
docker-compose version 1.24.0, build 0aa59064
docker-py version: 3.7.2
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.1.0j  20 Nov 2018
$ 
$ cat /etc/os-release
NAME="Container Linux by CoreOS"
ID=coreos
VERSION=2023.5.0
VERSION_ID=2023.5.0
BUILD_ID=2019-03-09-0138
PRETTY_NAME="Container Linux by CoreOS 2023.5.0 (Rhyolite)"
ANSI_COLOR="38;5;75"
HOME_URL="https://coreos.com/"
BUG_REPORT_URL="https://issues.coreos.com"
COREOS_BOARD="amd64-usr"
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした