LoginSignup
21
8

More than 3 years have passed since last update.

Ubuntu18.04 + VagrantでDocker環境お気楽構築

Posted at

Qiitaへの初投稿です。
何事もやってみるという事で慣れていこうと思いますのでよろしくお願いします。

この記事の対象者

  • vagrant up叩いてDocker環境を気楽に構築したい人
  • Dockerの環境がubuntu18.04に入ってないと禁断症状が出る人

前提条件

  • Vagrantが導入されている事

構築手順

1. Vagrantfile作成

$ vagrant init 

上記コマンドでVagrantfileが作成されます。

A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

You are now ready to vagrant up your first virtual environment!
と「早く!vagrant upしろ!」という熱を感じますが、無情にもファイルを下記の様に編集します。

Vagrantfile
Vagrant.configure("2") do |config|

  config.vm.box = "ubuntu/bionic64"
  config.vm.network "private_network", ip: "192.168.33.10"

  config.vm.provision :shell, path: "dockerinstall.sh"
end

これだけスッキリすればクールダウン出来ますね。

なお、dockerinstall.shの中身は下記の通りとなります。

dockerinstall.sh
#!/bin/bash

# this script target bionic64. 
# see also:https://docs.docker.com/install/linux/docker-ce/ubuntu/

# set up the repository
sudo apt update
sudo apt -y install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# point:fingeprint check
# 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]

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
# install docker
sudo apt update
sudo apt -y install docker-ce docker-ce-cli containerd.io

exit 0

Vagrantfileとdockerinstall.shなんて作ってられない忙しい人はこちらをどうぞ

2. Let's Vagrant up

手順1が完了したら
You are now ready to vagrant up your first virtual environment!
に呼応するように下記コマンドを叩いてください。

$ vagrant up

3.仮想環境内部でDocker確認

vagrant upが無事に終了したら、vagrant sshコマンドで仮想環境に入ります。

$ vagrant ssh

dockerコマンドを叩いて、下記のメッセージが出てきたらインストール出来てます。

vagrant@ubuntu-bionic:~$ docker

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/home/vagrant/.docker")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/home/vagrant/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/home/vagrant/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/home/vagrant/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit
   :
   :
   :

参考

21
8
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
21
8