1
5

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 5 years have passed since last update.

Windows+VagrantでDockerを動かすまで

Last updated at Posted at 2019-10-20

概要

  • Windowsで開発環境を構築したい。
  • Dockerさえ動けばあらかたの環境は作れるはずなので、Dockerを動かすまでをメモ。

Vagrant

1. インストール

ダウンロードしてインストールするだけ。
https://vagrantup.com

2. セットアップ

適当なディレクトリで vagnrant init すると、Vagrantfileが作成されるので以下の通り編集。

  • config.vm.box = "ubuntu/trusty64"
    (他のものにしたいときは https://app.vagrantup.com/boxes/search から選ぶ)

  • config.vm.synced_folter "../data", "vagrant_data"
    該当ディレクトリがないと起動時にエラーになるので作る。

3. 起動

Vagrantfileのあるディレクトリでやること。

  • vagrant up でVMを起動。
  • vagrant ssh でVMにssh接続する。

Docker

インストール

Docker公式のインストールガイドがあるので、基本的にはこれのとおりやる。
https://docs.docker.com/install/linux/docker-ce/ubuntu/

ただ、ハマりポイントがいくつかあったので解説。

4. Use the following command to set up the stable repository ... どれを使えばいいのよ

uname -a コマンドで調べられる。

vagrant@vagrant-ubuntu-trusty-64 ~> uname -a
Linux vagrant-ubuntu-trusty-64 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

trusty64の場合はx86_64 とあるので、x86_64 / amd64を使えば良い。

インストール時のコマンド

ガイドでは下記になっているが、

sudo apt-get install docker-ce docker-ce-cli containerd.io

こっちのほうがよさそう。

apt install docker-ce=18.06.1~ce~3-0~ubuntu

理由は下記。

  • docker-ce-clicontainerd.io がインストールできない(docker-ceに統合された?)
  • 最新の18.06.3~ce~3-0~ubuntuだと、コンテナの起動時にOCI runtime create failedになる

ユーザー Vagrant にdockerの実行権限を付与する

Vagrantでsshするとvagrantユーザーが使用されるが、このユーザーにはdockerの実行権限がない。
Warning: failed to get default registry endpoint from daemon ... となって失敗する)
sudo docker ... とすれば実行できるが、いちいちsudoつけるのめんどいので実行権限を付与する。

vagrant@vagrant-ubuntu-trusty-64 /vagrant_data> sudo groupadd docker
vagrant@vagrant-ubuntu-trusty-64 /vagrant_data> sudo usermod -g docker vagrant
vagrant@vagrant-ubuntu-trusty-64 /vagrant_data> sudo service docker restart

dockerが再起動したらsshし直す。

起動確認

vagrant@vagrant-ubuntu-trusty-64 ~> docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

備考

WSL2正式リリースはよう。

1
5
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
1
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?