Skip to content

Instantly share code, notes, and snippets.

@dracan
Last active October 1, 2016 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dracan/4e461921d6d20196fbe7da5fcfadd1f2 to your computer and use it in GitHub Desktop.
Save dracan/4e461921d6d20196fbe7da5fcfadd1f2 to your computer and use it in GitHub Desktop.
Using Docker with Vagrant on Windows

Setup Instructions

  1. Install Vagrant
  2. Open a command prompt
  3. Type vagrant plugin install vagrant-docker-compose to install the Docker Compose plugin
  4. Copy VagrantFile and docker-compose.yml from this Gist into a folder somewhere
  5. Edit the path in the second to last line of the VagrantFile to point to where you've copied it to. Use forward slashes - eg. /path1/path2/etc.

Usage Instructions

  1. Open a command prompt
  2. Change directory to where you copied the files to
  3. Type vagrant up
  4. Wait for it to finish its thing (this will take longer the first time, as it has to download the Linux distro, and Docker images)
  5. Job done! You should now be able to connect to Redis via port 6379 on localhost!!! :)
  6. You can play with the various docker commands and interact with your various containers by SSHing into the Linux VM with vagrant ssh.

Notes

  • If you need to get an shell into the Linux box, you can just type Vagrant ssh in the command prompt, and this should take your straight into the Linux bash shell. If you get an error saying OpenSSL hasn't been installed, then just update your path environment variable to include your Git bin folder - something like C:\Program Files\Git\usr\bin. Then restart your command prompt.
  • If you want to add other apps to the docker-compose file, also remember to open the port to your host machine by adding another config.vm.network "forwarded_port" line to your VagrantFile in the same way as I've done for Redis.
# mongodb:
# image: mongo
# ports:
# - "27017:27017"
# neo4j:
# image: neo4j/neo4j
# ports:
# - "7474:7474"
# volumes:
# - $HOME/neo4j-data:/data
redis:
image: redis
ports:
- "6379:6379"
restart: always
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
#config.vm.network "forwarded_port", guest: 27017, host: 27017 # Mongo
#config.vm.network "forwarded_port", guest: 7474, host: 7474 # Neo4j
config.vm.network "forwarded_port", guest: 6379, host: 6379 # Redis
config.vm.provision :docker
config.vm.provision :docker_compose, yml: "/vagrant/Docker/docker-compose.yml", run: "always"
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
config.vm.synced_folder "<host-path-to-docker-compose-file>", "/docker" # example for path might be "/code/myproject/docker"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment