Skip to content

Some research & findings around speeding up MacOS docker development, by running a VM.

Notifications You must be signed in to change notification settings

GioLogist/macos-docker-development-speed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Speeding up MacOS Docker Development, by using an Ubuntu VM w/Docker & Docker Compose

MacOS is slow at running Docker. It's a known issue. There are workarounds that can be used. Even with them, it's not as fast as when we run Docker directly on a Linux system.

In fact, running a Linux VM on your Mac and then using that VM to run Docker, is significantly faster than just running Docker on your mac. This repo was made for that very reason. And becuase of my frustration as a result.

You can use this repo to quickly scaffold an Ubuntu box, with Docker & Docker Compose pre-installed.

Note: There are probably other, even better approaches to this, such as provisioning docker or vagrant-docker-compose. But my goal here was to create a solution from scratch and learn more about the nuances of everything in the process.

Prerequisites

VirtualBox and Vagrant must be installed.

Development

Common commands for working with your box.

# starting 
vagrant up

# restarting
vagrant reload

# stopping
vagrant halt

# ssh inside
vagrant ssh

Customization

VagrantFile

Editing the Vagrantfile currently allows for the following

  • Specify the IP address you'll use to access your box
  • Specify resources to allocate for your box
  • Mount folders from your machine into the box. For example: mount the directory where your Docker container is located. Then, you can ssh into your box and start the container.

customize.sh

This file is run during provisioning of your box. Which happens when you first run vagrant up, or explicitly re-provision, as mentioned here.

This bash file currently is used to install software, such as Docker & Docker compose. Feel free to customize it to your liking.

"Gotchas"

There are a few gotchas when using this approach.

Permission issues when mounting volumes

When mounting volumes from MacOS to your VM, you may experience permission issues when your app attempts to make file writes. For example, you can experience this issue within a MySQL database container. This issue occurs when your data directory is mounted from MacOS to your Box, then from your Box to your Docker Container. You can see the issue described in more detail here.

In short, the workaround includes setting your Docker UID to be the same as the UID on the host (IE: your MacOS).

To do this, first identify the UID on your host

# run this on your host machine. for example: macOS
id -u

Update Docker to use the UID from your host machine. For example, in docker-compose.yml:

db:
  image: mysql
  user: "501" # UID from host

Additionally, you may need to use the nfs type for your synced folder. For example, in Vagrantfile

  config.vm.synced_folder "~/MyApps/MyContainer", "/home/vagrant/MyContainer", type: "nfs"

Additional

Todo

  • Make VagrantFile config options load from a YML file, for a better workflow & easy scaffolding
  • Create a way for others to benchmark and understand the major performance benefits documented in benchmarks.md

About

Some research & findings around speeding up MacOS docker development, by running a VM.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages