1
1

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.

Vagrant+VirtualBoxでのDocker環境

Posted at

目的

WindowsでDocker環境を構築するに際して「Docker Desktop for Window」を利用してみようとしましたが、
諸々の環境依存の問題に当たることがあり、過去の経験上で比較的問題のでることが少なかった
「Vagrant+VirtualBox」の環境上にDocker環境を作成したものです

方針

  • Windowsの依存問題を避けるため、VMはLinux系のもの
  • VM/コンテナを両方起動することの無駄には目をつぶる

Vagrant起動スクリプト

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

  config.vm.box = "centos/7"
  config.ssh.insert_key = false

  config.vm.network "forwarded_port", guest: 80, host: 80   # HTTP
  config.vm.network "forwarded_port", guest: 443, host: 443  # HTTPS
  config.vm.network "forwarded_port", guest: 3306, host: 3306  # MySQL
  config.vm.network "forwarded_port", guest: 6379, host: 6379  # Redis
  
  config.vm.synced_folder "./workDir", "/home/vagrant/mnt/workDir"
  
  # Docker
  config.vm.provision :docker, run: "always"

  # docker-compose
  config.vm.provision :docker_compose,
    compose_version: "1.27.4",
    run: "always"
end

個別の補足

  config.vm.box = "centos/7"
  config.ssh.insert_key = false

今回はCentOS7を採用
2行目はSSHのキーを省略する設定、ローカル環境でのみ使用するためこの設定としていますが、
あまり好ましくない設定と思われるので、本記事を参考にする際はきちんと調べて適切に設定してください

  config.vm.network "forwarded_port", guest: 80, host: 80   # HTTP

VirtualBoxのポートフォワーディングに関する設定
開発環境に必要なポートを定義しています

  config.vm.synced_folder "./workDir", "/home/vagrant/mnt/workDir"

ホストマシンとゲストマシンのディレクトリの同期設定です
「/home/vagrant/mnt/」は「Vagrant+VirtualBox+CentOS7」の環境のマウント用パスです

  config.vm.provision :docker, run: "always"
(※中略)
  config.vm.provision :docker_compose,

Dockerおよびdocker-composeをインストールするための設定です

あとがき

かなりザックリすぎに記事を書いた自覚はあるので、後日時間があれば追記修正する気持ちはあります……

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?