Coder Social home page Coder Social logo

docker-mac-vagrant's Introduction

Docker in Vagrant

This repository automates the provisioning of a Vagrant VM that acts as a hypervisor. In other words, it effortlessly replaces the slow parts of Docker for Mac. Your code runs faster, battery lasts longer and fans spin less - and you don't have to change anything about your projects.

D4M is slow. Primarily because of its osxfs/grpcfuse sharing filesystem. On the other hand, Parallels has their own proprietary fs sharing driver, and it works at almost native speeds. Unfortunately for us all, Vbox and VMWare do not seem to have the same performance.

Setting up

  1. Install and set up vagrant VM:
    ./setup.sh
  2. Set your preferred shared folder in the .env file, for example SHARE_PATH="$HOME/Sites/"
  3. Thats it, start vagrant with vagrant up.
  4. Add the following to VScode Settings:
    "docker.explorerRefreshInterval": 10000,
    "docker.host": "ssh://vagrant@workbox",

Usage

There are various ways to code in this setup. I have outlined my decisions in a thorough article.

Naked

๐Ÿ˜ช Files Editor/Interpreter Runtime
Host ๐Ÿ”ป ๐Ÿ”ป
VM ๐Ÿ”ป ๐Ÿ”ป

You can just go oldschool and keep coding on your local machine. Use your editor of choice. All the files will be sync-ed over to the containers at nearly native speeds. In other words, you run your Docker project as you usually would.

Reminder: You will need however, to have the language you use installed on your machine, if you hope to have intellisense.

Remote Interpreter

๐Ÿ’ฟ Files Editor/Interpreter Runtime
Host ๐Ÿ”ป
VM ๐Ÿ”ป ๐Ÿ”ป ๐Ÿ”ป

A better (albeit weird at first) way would be to share the code from your machine to the Parallels VM. Start containers. Refer to Remote coding How-tos section for directions on how to use the editors.

Here's an example - Host computer has no idea what Python is. I start the Docker container with Python inside. I click a button in VSCode, and it magically "teleports" itself into the container. You can now literally code within the container, without ever leaving the comfort of your editor. Of course, the files are on a volume so any changes you make are safely in sync with your local folder.

Container-first

๐Ÿ›ฐ Files Editor/Interpreter Runtime
Host
VM ๐Ÿ”ป ๐Ÿ”ป ๐Ÿ”ป

Important: Use container-first Branch!

Feeling adventurous? Don't use sharing at all. Provision the VM with your SSH key, and download your projects inside the VM. Use the rest the same as you would in the Remote Interpreter segment above. You will get an insane speed boost since you don't have any shared files between host and the VM - everything is only in VM.

Remote coding How-tos

I have written an extensive article on the topic, in short:

  • VSCode has a built in "Attach to remote Container" capability. It spawns a real editor and you work directly with the native interpreter within the container.
  • JetBrains "thick-ide" products like PHPStorm have a similar capability to be located on your host, but use a remote interpreter from within the container.

docker-mac-vagrant's People

Contributors

borisceranic avatar markomitranic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

docker-mac-vagrant's Issues

how to catch Xdebug connections?

Hi! Thanks for this repository, it really makes my Mac breathe freely)

Have you ideas, how to catch debug connection in my IDE (phpstorm)?

sed command fails on macos 11.6

I followed the simple steps to setup everything and start up, but the trigger-up.sh script failed during execution of
vagrant up

Error Message:
workbox: sed: 1: "/Users/.../.ssh/config": command c expects \ followed by text

The reason for this seems to be different behavior of sed on different versions of macos.
See https://stackoverflow.com/questions/4247068/sed-command-with-i-option-failing-on-mac-but-works-on-linux

For me it worked after adding a backup suffix to the sed command in trigger-up.sh, like:
# Prepend content to the start of the file sed -i .bak '1s;^;Include config.d/*'"\\${nl}\\${nl}"';' "$HOME/.ssh/config"

But maybe the use of the -e flag as suggested in stackoverflow, could avoid a os switch to resolve this issue.

Failed when run `vagrant up`

There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "cb85277f-27f8-451c-9cc9-5fbe87de6af9", "--type", "headless"]

Stderr: VBoxManage: error: The virtual machine 'docker-mac-vagrant_workbox_1637584841804_71894' has terminated unexpectedly during startup with exit code 1 (0x1)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine

Mac15 2017 Intel

what can be the reason?

Ask me for password ?

Hello,

I'm trying to use your approach but when I want to run docker-compose shell ask me for a password. Maybe I've missed something?

Screenshot 2021-09-01 at 16 33 07

vagrant up fails

Hey, thanks a lot for your articles it was very interesting !

I'm trying the vagrant solution and im stuck at the vagrant up spitting this error

1: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/plugins/kernel_v2/config/vm.rb:815:in `new' /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/plugins/kernel_v2/config/vm.rb:815:in `initialize': no implicit conversion of nil into String (TypeError) (click for stack trace)
Bringing machine 'default' up with 'parallels' provider...
Traceback (most recent call last):
        31: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/batch_action.rb:86:in `block (2 levels) in run'
        30: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/machine.rb:201:in `action'
        29: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/machine.rb:201:in `call'
        28: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/environment.rb:613:in `lock'
        27: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/machine.rb:215:in `block in action'
        26: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/machine.rb:246:in `action_raw'
        25: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/runner.rb:89:in `run'
        24: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/util/busy.rb:19:in `busy'
        23: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/runner.rb:89:in `block in run'
        22: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/builder.rb:149:in `call'
        21: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/warden.rb:48:in `call'
        20: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/builtin/call.rb:53:in `call'
        19: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/runner.rb:89:in `run'
        18: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/util/busy.rb:19:in `busy'
        17: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/runner.rb:89:in `block in run'
        16: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/builder.rb:149:in `call'
        15: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/warden.rb:48:in `call'
        14: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/warden.rb:127:in `block in finalize_action'
        13: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/warden.rb:48:in `call'
        12: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/builtin/handle_box.rb:56:in `call'
        11: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/warden.rb:48:in `call'
        10: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/warden.rb:127:in `block in finalize_action'
         9: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/warden.rb:48:in `call'
         8: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/action/builtin/config_validate.rb:15:in `call'
         7: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/config/v2/root.rb:66:in `validate'
         6: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/config/v2/root.rb:66:in `each'
         5: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/lib/vagrant/config/v2/root.rb:71:in `block in validate'
         4: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/plugins/kernel_v2/config/vm.rb:810:in `validate'
         3: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/plugins/kernel_v2/config/vm.rb:810:in `each'
         2: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/plugins/kernel_v2/config/vm.rb:815:in `block in validate'
         1: from /opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/plugins/kernel_v2/config/vm.rb:815:in `new'
/opt/vagrant/embedded/gems/2.2.13/gems/vagrant-2.2.13/plugins/kernel_v2/config/vm.rb:815:in `initialize': no implicit conversion of nil into String (TypeError)

If i click on this file ...../config/vm.rb at line 815 there is
hostpath = Pathname.new(options[:hostpath]).expand_path(machine.env.root_path) if that can help

I have tried to reinstall vagrant-hostsmanager plugin and downgrade vagrant 2.2.18 to 2.2.13 and still have the issue. (random stuff i found, i have no clue what i'm doing :D)

Here is my config files

Vagrantfile
#-*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  # Load variables from .env
  config.env.enable
  env_box_name = ENV["BOX_NAME"]
  env_ram = ENV["RAM_MEMORY"]
  env_cpus = ENV["CPU_COUNT"]
  env_share_path = ENV["SHARE_PATH"]

  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  
  config.vm.box = "bento/ubuntu-20.04"
  config.vm.synced_folder env_share_path, env_share_path
  config.ssh.extra_args = ["-t", "cd #{env_share_path}; bash --login"]

  config.vm.provider "parallels" do |prl|
    prl.memory = env_ram
    prl.cpus = env_cpus
    prl.name = env_box_name
    prl.update_guest_tools = true
  end

  config.vm.provision :docker
  config.vm.provision "shell", path: "provision.sh"

end
.envrc
export BOX_NAME="workbox"
export RAM_MEMORY=8192
export CPU_COUNT=4
export BOX_STATIC_IP="192.168.50.4"
export SHARE_PATH="/Users/admin/Site"
export ROOT_PATH="/Users/admin/Site"

Thanks for any help that will come

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.