I was doing team development using Docker for Mac, but since it is slow, let's stop Docker for Mac and start a virtual environment and create an explosive Docker environment! !! I came to.
On Linux, the VFS is shared between the host and the container, so the reflection without overhead is guaranteed. However, on macOS (and other non-Linux platforms), there is significant overhead for full consistency ... Docker Japanese document and other Qiita articles also said that, but I don't really understand ... For the time being, the Docker for Mac file sharing system seems to mount slowly on osxfs, The main reason is that the FSEvents API of OSX and the Linux ’s inotify API are mapped. Slow cause
What is the difference between Docker for Mac and the environment (Virtual Box + Docker) to be built this time
?
Abandon Docker for Mac, which significantly reduces DX, and get the fastest Docker environment for Mac
The above article was extremely easy to understand! !! The figure is helpful (; ∀ ;)
Mac OS Catalina 10.15.7
20.10.0-beta1
Vagrant 2.2.13
Ubuntu 18.04.5 LTS
I can see many steps, but let's do our best ... (laughs)
Use Homebrew to install the necessary tools. Homebrew installation
brew cask install virtualbox
brew cask install vagrant
Download Vagrant Box (OS). (It took quite a while)
vagrant box add ubuntu/bionic64
After the download is complete, you can check it with the following command
vagrant box list
ubuntu/bionic64 (virtualbox, 20200229.0.0)
Install the required Vagrant Plugin. We will discuss mutagen later.
vagrant plugin install vagrant-disksize vagrant-hostsupdater vagrant-mutagen vagrant-docker-compose
Vagrant init in the development directory
cd ~/my_app (Move to development directory)
vagrant init ubuntu/bionic64 (Initialize with vagrant)
The following sentence will appear, so you can create a 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.
We will edit the Vagrantfile
! !! !!
Edit the contents of the Vagrant file as follows!
config.vm.hostname
is OK in the development directory!
If you don't understand anything else
Vagrant command and Vagrantfile settings memo
It was easy to understand if you look at the "vagrantfile settings" in the above article. Thank you(:_;)
~/my_app/Vagrantfile
Vagrant.configure('2') do |config|
config.vm.box = 'ubuntu/bionic64'
config.vm.hostname = 'my_app'
config.vm.network :private_network, ip: '192.168.50.10'
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.provider :virtualbox do |vb|
vb.gui = false
vb.cpus = 4
vb.memory = 8192
vb.customize ['modifyvm', :id, '--natdnsproxy1', 'off']
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'off']
end
config.disksize.size = '30GB'
config.mutagen.orchestrate = true
config.vm.synced_folder './', '/home/vagrant/app', type: "rsync",
rsync_auto: true,
rsync__exclude: ['.git/', 'node_modules/', 'log/', 'tmp/', 'vendor']
config.vm.provision :docker, run: 'always'
config.vm.provision :docker_compose
end
If the host side path of config.vm.synced_folder is set to "./ "
, it will be easier because there is no need to rewrite the path for each work environment when sharing work.
This completes the preparation of Vagrant + VirtualBox.
Synchronize the edited file on Mac and Linux. This is achieved with a tool called Mutagen. Install mutagen with the following command. (This also took time)
brew install mutagen-io/mutagen/mutagen
After installation, create a mutagen configuration file mutagen.yml. Create it in the same directory as Vagrantfile.
~/my_app
touch mutagen.yml
The contents are as follows.
~/my_app/mutagen.yml
sync:
app:
mode: "two-way-resolved"
alpha: "./"
beta: "my-app:/home/vagrant/app"
ignore:
vcs: true
paths:
- "/node_modules"
- "/log"
- "/tmp"
Then start the VM with $ vagrant up and Mutagen will do a two-way file sync. This synchronization is bi-directional, near real-time, and is achieved by transferring files rather than mounting the filesystem, so there is almost no overhead when finally mounted in a Docker container.
An error occurred after executing the command ,,,,,
~my_app
vagrant up
/Users/hoge/.vagrant.d/gems/2.4.9/gems/vagrant-mutagen-0.1.2/lib/vagrant-mutagen/Mutagen.rb:22:in `initialize': No such file or directory @ rb_sysopen - /Users/hoge/.ssh/config (Errno::ENOENT)
You say you don't have config
(sweat)
Let's make it! !!
~my_app
touch /Users/hoge/.ssh/config
once again! !!
~my_app
vagrant up
It seems that this time it was done well ε- (´∀ ` *) Hot
vagrant ssh
Then, this time, some kind of update information ...
New release ''20.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
You shouldn't do this.
vagrant box add ubuntu/bionic64
It seems that it is necessary to download the OS that matches the version firmly, so ...
The following command is an example when docker-compose.yml exists in the project directory.
cd app
docker-compose up
Recommended Posts