20
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WSL + Ubuntu 上でdocker-composeを動作させる

Last updated at Posted at 2020-02-01

確認環境

📀WSL with Ubuntu 20.04LTS
📀WSL with Ubuntu 18.04LTS

docker のインストール

公式の通りに、Docker CEをインストールします。

Docker の公式 GPG 鍵を追加します。

$ sudo apt-get update
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

鍵の fingerprint(フィンガープリント)が 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 と表示されるのを確認します。

$ sudo apt-key fingerprint 0EBFCD88

pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

Dockerの stable (安定版)リポジトリをセットアップします。

$ sudo -E add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Docker CE をインストールします。

$ sudo apt-get install docker-ce

docker-compose のインストール

docker-compose は複数のコンテナを使う Docker アプリケーションを定義・実行するためのツールです。

sudo -i
curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

/download/の後に続くバージョン指定は、公式サイトを確認の上最新のバージョンへ変更してください。

:rocket: Dockerの起動

Dockerサービスを起動させます。これで、Dockerコンテナを動かせるようになります。

$ sudo service docker start

動作確認

👀以下のコマンドで確認します。

$ curl -O https://keinos.github.io/hello-docker-compose/docker-compose.yml
$ docker-compose up

成功すると以下のように表示されます。

Starting hello_hello_1 ... done
Attaching to hello_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  |
hello_hello_1 exited with code 0

参考

WSLでdockerのインストールからdocker-composeまで動かす
最もシンプルな docker-compose.yml の hello-world

20
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?