Giter VIP home page Giter VIP logo

docker-machine-for-mac's Introduction

Docker for Mac - Docker Machine / Vagrant / Ansible

⚠️ I no longer use this repo and recommend using colima instead ⚠️

If you need docker and kernel modules to support things like SCTP, IP_VS, WireGuard etc. then this project might be for you.

These Vagrant boxes are intended to replace Docker for Mac and utilises docker-machine, Vagrant, VirtualBox and Ansible to provide a fully featured linux vm.

Motivation: Docker for Mac was proving to be a workflow pain rather than a workflow gain. It was slowing down my 16" Macbook Pro (32GB RAM, 6 CPUs), draining the battery, and causing the fans to constantly spin at full speed. There had also been occurrences where kernel modules had been removed, rendering it difficult to do system development.

Background

Vagrant and VirtualBox can be used to quickly build or rebuild virtual servers.

This Vagrant profile installs docker using the Ansible provisioner and finishes up with the docker-machine configuration.

Getting Started

Each docker-machine directory contains a Vagrantfile for a different base operating systems (hereafter this folder shall be called the [vagrant_root]), which tells Vagrant how to set up your virtual machine in VirtualBox.

To use the vagrant file, you will need to have done the following:

  1. Download and Install VirtualBox
  2. Download and Install Vagrant
  3. If you want to completely remove Docker for Mac run this script (recommended)
  4. If you removed Docker for Mac you'll then need to Download and install the docker-cli binary
  5. Install Docker Machine docker-machine
  6. Install Ansible
  7. Open a shell prompt (Terminal app on a Mac) and cd into the folder containing the Vagrantfile of the target operating systems that you want to build.

Once all of that is done, you can simply type in make build, and Vagrant will create a new VM, install the base box, and configure it to work with docker.

Once the new VM is up and running, you should see the message:

Docker Machine setup was successful
To connect to this host run "eval `docker-machine env <vagrant_hostname>`". To make this your default docker machine add the command or the output from "docker-machine env <vagrant_hostname>" to your ~/.bash_profile

Setting up your hosts file

If you want to modify your host machine's hosts file (/etc/hosts), to add the docker machine hostname you can do so adding the line below:

<vagrant_ip>  <vagrant_hostname>

eg.

192.168.33.3  docker-debian-10

(Where docker-debian-10) is the hostname you have configured in the Vagrantfile).

If you'd like additional assistance editing your hosts file, please read How do I modify my hosts file? from Rackspace.

Managing your docker-machine

The setup of your docker machine is handled during the build stage. If you need to update or re-do this in any way the following commands are helpful.

command description
make build build a the docker-machine vm and configure for use with docker
make destroy this will destroy the vagrant box and clean up the .vagrant directory
make up the same as vagrant up, you can use this to start the docker-machine vm if it has already been built and needs to be started again.
make down the same as vagrant halt, you can use this to shutdown your docker-machine vm.
make docker-machine-add add the vagrant box as a docker machine
make docker-machine-rm remove the vagrant box as a docker machine
make docker-machine-check check that the vagrant box is correctly setup as a docker machine

SSH access

If you need or want ssh access to the vm you can ssh in with two methods.

  1. The Vagrant method: from within the machines directory execute:

    vagrant ssh

  2. The docker-machine method: from anywhere execute the command:

    docker-machine ssh

Mounting Volumes

The docker machine mounts the "/Users" folder in the docker VM to allow you to continue using the the existing functionality to mount volumes from the Mac locations.

eg.

docker run -d -v ~/dev/project/config.json:/opt/my_app/config.json -v $PWD:/data centos:7

More locations can be added if required in the Vagrant file. After updating with the new location execute vagrant reload to take effect.

eg.

config.vm.synced_folder "/Library", "/Library"

Exposing Ports

Any time you want to expose a port from docker you need to remember that the docker host will have changed from localhost to the IP address on the VM. If anyone has any good ideas to fix that magic let me know via the issues. If you really want to use localhost you can set a range in virtual box and port forward the ports that way.

eg. exposing ports -p 8080:80 in docker will mean to query that port from your mac you would query the VM IP instead.

curl http://192.168.33.3:8080

or if you configured your /etc/hosts as per the above instructions.

curl http://docker-debian-10:8080

Communicating with Mac OS localhost and DNS

The existing magic hostname (host.docker.internal) that lets docker containers talk to services on the Mac's localhost has been configured to use the Mac's interface IP address connected to the VM's private network. Any services on the Mac would need to be listing on this interface in order for this to work.

Other custom hostnames can be configured if required by adding the variable dnsmasq_custom_hosts to the resources/vars/main.yml file.

Usage:

dnsmasq_custom_hosts:
  - hostname: custom.hostname.local
    ip_address: 192.168.3.1

SELinux

CentOS Stream8 Docker Machine's docker daemon is configured with SELinux support enabled (selinux-enabled).

Author Information

James Stenhouse

Vagrant file and Readme adapted from: Jeff Geerling, Ansible Vagrant Examples

docker-machine-for-mac's People

Contributors

stenh0use 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  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  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  avatar

docker-machine-for-mac's Issues

Deprecation of docker machine?

Hi!
Thanks for sharing a way out of Docker for Desktop and its resource-intensive approach.
README.md instructs to install Docker Machine with this link. Sadly that linked page says that docker-machine is now deprecated and that ... Docker Desktop replaces it :( Was it already the case when you kindly set up that repo, or is it a new development that will hamper its viability?
Thanks for clarifying for a historically linux Docker user new to Docker on macOS :)

Please add a license to this repo

First, thank you for sharing this project with us!

Could you please add an explicit LICENSE file to the repo so that it's clear
under what terms the content is provided, and under what terms user
contributions are licensed?

Per GitHub docs on licensing:

[...] without a license, the default copyright laws apply, meaning that you
retain all rights to your source code and no one may reproduce, distribute,
or create derivative works from your work. If you're creating an open source
project, we strongly encourage you to include an open source license.

Thanks!

Running on Apple Silicon

Hi, this looks like a great replacement for docker for Mac. Have you maybe tried to run this on an ARM Mac?
I tried setting it up on an M2 MacBook Air. Setting up docker-cli is easy, and I got docker-machine via brew, no problem.
The issue seems to be VirtualBox. The Apple Silicon version is still in beta.
I tried installing it via brew (brew install --cask homebrew/cask-versions/virtualbox-beta) or via the pkg from the website, but in both cases I run into the following issue while doing make build:

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

Command: ["hostonlyif", "create"]

Stderr: 0%...NS_ERROR_FAILURE
VBoxManage: error: Failed to create the host-only adapter
VBoxManage: error: VBoxNetAdpCtl: Error while adding new interface: failed to open /dev/vboxnetctl: No such file or directory
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component HostNetworkInterfaceWrap, interface IHostNetworkInterface
VBoxManage: error: Context: "RTEXITCODE handleCreate(HandlerArg *)" at line 105 of file VBoxManageHostonly.cpp

make: *** [vagrant-up] Error 1

After some google research it looks like some issue with macOs permissions for Kernel extensions? not sure though.

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.