2
0

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.

docker (docker-compose) on vagrant環境を構築する

Last updated at Posted at 2021-03-18

前提

・vagrant,virtualboxがインストールされている

構築手順

・vagrantfileの作成(vagrant initコマンドでvagrantfileが作成される)

$ vagrant init

・プラグインのインストール

$ vagrant plugin install vagrant-vbguest
$ vagrant plugin install vagrant-docker-compose

・vagrantfileを以下のように編集


# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  # config.vm.network "private_network", ip: "192.168.33.10"
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = false
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  # ホスト側のファイルを仮想環境にマウント
  config.vm.synced_folder "./data", "/vagrant"
  config.vm.provision :docker#, run: 'always'
  config.vm.provision :docker_compose
end

・vagrant upコマンドで仮想環境構築

$ vagrant up

・仮想環境にログイン

$ vagrant ssh
# 環境構築完了
vagrant@ubuntu-bionic:/vagrant$

上記のようになれば環境構築完了

vagrantfileの変更内容を仮想環境に反映したいとき

  • 仮想環境を削除してから作り直す必要がある。
    • vagrant reloadでできるという記事もあったが、うまく行かないときがあった。)

・ docker,docker-composeがうまくインストールされるか確認

# docker
vagrant@ubuntu-bionic:/vagrant$ docker
# --- 実行結果-------
Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers
・・・・・・・・・・
# -------------
# docker-compose
vagrant@ubuntu-bionic:/vagrant$ docker-compose
# --- 実行結果 ----

Define and run multi-container applications with Docker.

Usage:
  docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
  docker-compose -h|--help

# --------------

・ ファイルがマウントされていること確認

vagrant@ubuntu-bionic:/vagrant$ cd /vagrant/
vagrant@ubuntu-bionic:/vagrant$ ls
test

$ vagrant destory
$ vagrant up
2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?