{"id":27334959,"url":"https://github.com/dmuth/docker-in-vagrant","last_synced_at":"2025-04-12T14:46:45.177Z","repository":{"id":65895067,"uuid":"564591778","full_name":"dmuth/docker-in-vagrant","owner":"dmuth","description":"Alternative to Docker Desktop for Mac. This project lets you deploy Docker inside of a Vagrant VM in Virtualbox.","archived":false,"fork":false,"pushed_at":"2024-04-01T21:53:32.000Z","size":101,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-02T06:07:29.703Z","etag":null,"topics":["desktop","docker","mac","vagrant","virtualbox"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmuth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-11-11T03:19:10.000Z","updated_at":"2023-10-06T15:59:19.000Z","dependencies_parsed_at":"2024-04-01T22:51:05.017Z","dependency_job_id":null,"html_url":"https://github.com/dmuth/docker-in-vagrant","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmuth%2Fdocker-in-vagrant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmuth%2Fdocker-in-vagrant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmuth%2Fdocker-in-vagrant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmuth%2Fdocker-in-vagrant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmuth","download_url":"https://codeload.github.com/dmuth/docker-in-vagrant/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248585248,"owners_count":21128974,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["desktop","docker","mac","vagrant","virtualbox"],"created_at":"2025-04-12T14:46:44.256Z","updated_at":"2025-04-12T14:46:45.166Z","avatar_url":"https://github.com/dmuth.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[**Edit:** While this project is still in good shape, I'd strongly recommend checking out [OrbStack](https://orbstack.dev/) instead.  Orbstack is a drop-in replacement for Docker, and it works great on both Intel and M1 Macs!]\n\n# Docker in Vagrant\n\n\u003cimg src=\"./img/logo.png\" align=\"right\" width=\"250\" /\u003e\n\nThis project lets you deploy Docker inside of a Vagrant VM in Virtualbox.\n\nIt is intended as a replacement for Docker Desktop for Mac OS/X users.  I've tested it with some of my open source projects, including [FastAPI Httpbin](https://github.com/dmuth/fastapi-httpbin) and [Grafana Playground](https://github.com/dmuth/grafana-playground).  I'd like to think it's bug-free, but if there are any issues, my contact info is at the bottom of this README.\n\n\n## Features\n\n- Easily spin up a VM with Docker already installed and running, using `bin/start.sh`.\n- Packages installed via `yum` will be cached to disk outside of the VM, making future builds less network intensive.\n- Sshd is configured to support up to 100 sessions to speed up operations with `docker-compose`.\n- Docker images can be saved to disk outside the VM with `docker-save-images.sh`.\n- Docker images will be automatically loaded from disk outside the VM at startup with `docker-images-load.sh`.\n\n\n## Prerequisites\n\n- [Docker CLI tools](https://formulae.brew.sh/formula/docker)\n- [Virtualbox](https://www.virtualbox.org/)\n- [Vagrant](https://www.vagrantup.com/)\n- [Pipeviewer](https://catonmat.net/unix-utilities-pipe-viewer)\n  - This is used for watching progress.  Install with `brew install pv`.\n\n\n## Installation\n\n- Clone this repo\n- Run the script `./bin/start.sh` to start the VM.\n  - This will also configure the VM so that Docker is installed and can be run as a non-root user, SSH is set up to accept more simultaenous connections, etc.\n- The script will then print out some additional configuration instructions, which I will summarize here:\n  - Run this so that when you spawn a new shell, Docker will know to talk to the VM:\n    - `echo \"export DOCKER_HOST=ssh://vagrant@127.0.0.1:2222\" \u003e\u003e $HOME/.bashrc`\n  - Run this so that aliases are set when you spawn a future shell:\n    - `echo . $(pwd)/bin/docker-aliases-bash.sh \u003e\u003e $HOME/.bashrc`\n  - These instructions are for the `bash` shell.  If you are using a different shell, you'll have to touch a different file.\n\nFinally, add this into `$HOME/.ssh/config` so that you can connect to the VM via SSH:\n```\nHost 127.0.0.1\n     ControlMaster auto\n     ControlPath ~/.ssh/master-%r@%h:%p\n     ControlPersist yes\n     StrictHostKeyChecking no\n     UserKnownHostsFile /dev/null\n     IdentityFile $(pwd)/.vagrant/machines/default/virtualbox/private_key\n     IdentitiesOnly yes\n```\n\n**Be sure to start a new bash shell after updating your .bashrc so the changes take effect!**\n\n\n## Usage\n\n- Start by running `docker ps`, and make sure you can connect to the Docker instance.\n- Then try running `docker run hello-world` to perform a basic test of Docker\n- Some additional aliases that you may find useful:\n  - `docker-start` - Start the VM containing Docker\n  - `docker-stop` - Stop the VM containing Docker\n  - `docker-destroy` - Destroy the VM containing Docker.  This will remove any Docker images and volumes!\n  - `docker-aliases` - Show all aliases that were set up by this app\n- For troubleshooting\n  - `docker-check-time` - Check the system time versus the VM time.  Run `docker-restart` if they've fallen out of sync.\n\n\n## Development\n\nIf you've set up the suggested aliases, they'll make development simpler.  Here are a few things\nI like to use:\n- `docker-destroy; docker-start` - Blow away and build a new VM\n- `docker-ssh` - Open an SSH connection to the VM.\n\n\n### Other Useful Utilities\n\n- `bin/status.sh` - Reports back the status of the VM\n- `bin/start.sh` - Already covered, this starts up the VM and loads the SSH key.\n- `bin/restart.sh` - Restart the VM.  Will not start it if stopped.\n- `bin/stop.sh`  - This stops the VM temporarily.\n- `bin/destroy.sh` - This destroys the VM.\n- `bin/docker-images-load.sh` - This loads Docker images which were saved outside of the VM. Used by `start.sh`.\n- `bin/docker-images-save.sh` - Save existing Docker images outside of the VM. Run manually.\n- `bin/docker-images-list.sh` - List all Docker images that have been saved outside of Docker.\n- `bin/provision.sh` - Run the `vagrant provision` command.  Optional environment variables to speed up testing and debugging include:\n  - `SKIP_APT`, `SKIP_DOCKER`, `SKIP_SSH`, and `SKIP_TIME`.\n\n\n## Frequently asked questions\n\n\n### FAQ: I can't mount any directories in Docker!\n\n- Edit `Vagrantfile`, look for the section with `config.vm.synced_folder`, and add the directory you'd like to be able to mount\n- Run `docker-restart` to restart the VM.\n\n\n### FAQ: You get a \"Permission denied (public key)\" error when trying to use a Docker command.\n\nDid you add the key to `ssh-agent`?  If so, did you destroy and rebuild the instance?  You'll need to re-add the key since a new SSH key was generated as part of that process.\n\n\n### FAQ: Sometimes when using docker-compose on a bunch of containers at once, I see an SSH error!\n\nI am trying to reproduce this reliably, but it seems that this happens when sshd gets too many incoming connections at once!  If it does happen to you, just run the command again.  Docker commands such as `up` and `kill` are idempotent, so running them more than once should not cause any harm.\n\n\n### FAQ: I get an error saying \"WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!\"\n\nIt's all good--it means you have a reference to the VM sitting in your `$HOME/.ssh/known_hosts` file.\nTake a look through that file and see if you see any lines that start with `[127.0.0.1]:2222` or similar.\nThe tell is the `2222`, which is the port that Vagrant hosts listen on.  Delete those lines manually \nor with this command:\n\n`sed -i -e '/\\[127.0.0.1\\]:2222/d' ~/.ssh/known_hosts`\n\nNote that the script `bin/start.sh` should do this automatically, and you should only have to\ndo this if something has gone wrong.\n\n\n### FAQ: I get an error that says \"Cannot connect to the Docker daemon\" or similar!\n\nIf the VM is running, did you tell the Docker CLI tools about it?  You can do so on the command\nline with something like this:\n\n`export DOCKER_HOST=ssh://vagrant@127.0.0.1:2222`\n\n\n### FAQ: I run a command like docker-compose and some containers start, but I still get SSH errors?\n\nIf you are trying to do stuff with many containers at once, you may need a higher [MaxStartups value](https://stackoverflow.com/questions/4812134/in-sshd-configuration-what-does-maxstartups-103060-mean) in `/etc/ssh/sshd_config`.  By default it is set to `100:30:100`, which should handle most cases, but if the value needs to be increased, just be sure to run `systemctl restart sshd` after doing so.\n\n\n### FAQ: Are there bugs?\n\nUnfortunately, yes.  There seem to be some low-level filesystem issues that trip up a few things.  In detail:\n\n\n### FAQ: Splunk Lab Issues\n\nYeah I know this isn't a question.\n\nI tried spinning up an instance of [Splunk Lab](https://github.com/dmuth/splunk-lab), and saw no logs making it into Splunk and plenty of these errors:\n\n```\n11-15-2022 01:45:31.042 +0000 ERROR StreamGroup [217 IndexerTPoolWorker-0] - failed to drain remainder total_sz=24 bytes_freed=7977 avg_bytes_per_iv=332 sth=0x7fb586dfdba0: [1668476729, /opt/splunk/var/lib/splunk/_internaldb/db/hot_v1_1, 0x7fb587f7e840] reason=st_sync failed rc=-6 warm_rc=[-35,1]\n```\n\nBest I can figure for a root cause is that Splunk does some low-level filesystem things that don't play nicely with how VirtualBox does directory mounting to the host OS.  To work around this, disable sharing of Splunk's data directory by setting `SPLUNK_DATA=no`, like this:\n\n`SPLUNK_DATA=no SPLUNK_EVENTGEN=yes ./go.sh`\n\nBy doing this, any data ingested into Spunk will not persist between runs.  But to be fair, Splunk Lab is meant for development usage of Splunk, not long-term usage.\n\n\n### Httpbin Issues\n\nI know this isn't a question either.\n\nMy [FastAPI Httpbin project](https://github.com/dmuth/fastapi-httpbin) doesn't behave right when\nrun in development mode in a Docker container spawned by this app.  Specifically, the functionality\nof FastAPI to reload itself when a file is changed does not seem to work.  For now, the workaround\nis to restart the FastAPI server when new changes are to be tested, or to not run it in a container \nin the first place.\n\nProduction use is unaffected.\n\n\n## Get In Touch\n\nIf you run into any problems, feel free to [open an issue](https://github.com/dmuth/docker-in-vagrant/issues).\n\nOtherwise, you can find me [on Twitter](https://twitter.com/dmuth), [Facebook](https://facebook.com/dmuth), or drop me an email: **doug.muth AT gmail DOT com**.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmuth%2Fdocker-in-vagrant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmuth%2Fdocker-in-vagrant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmuth%2Fdocker-in-vagrant/lists"}