Access Docker features when using Vagrant

I’ve been using Vagrant for some time and am now exploring Docker. I’ve always loved Vagrant for its simplicity. Right now, I’m trying to use the Docker provider within Vagrant. I’m using the following Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.provider "docker" do |d|
    d.image = "fgrehm/vagrant-ubuntu:precise"
  end
end

My understanding is that I can just run vagrant up. I can then run the Docker container using vagrant docker-run -- <command>.

  • How can I save my RSA KEY in my Docker Machine?
  • What is the proper set up for Maven to communicate with Docker daemon on Mac?
  • subgit timeout waiting for pid file
  • Docker volume not available during execution
  • Is it possible to view docker-compose logs in the output window running in Windows?
  • How can I setup a instance EC2 with docker and access it with the IP?
  • So far so good. What makes Docker so awesome is the fact that you can mess around and commit changes. I do not understand is how to incorporate this in my workflow when using the Docker provider for Vagrant. E.g. how do I run docker commit to commit the state of the container? I’d expect some kind of vagrant docker-commit, but this does not exist?


    Edit: In hindsight, I think this is not the way you should be using Vagrant/Docker. Though it is claimed that both tools complement each other, my opinion is that they do not (yet) play really well together. Right now, we’re using Dockerfiles to build our images. Additionally, we made a set of bash scripts to launch a container.

  • How to run a docker machine on homestead when port 80 is already in use?
  • Error accessing cgi script inside Docker container, Operation not permitted: Couldn't bind unix domain socket
  • Docker containers slow after restart in Azure VM
  • Docker: getcwd: cannot access parent directories
  • Running Docker behind proxy
  • Configuration or option in docker run to fail if host volume has no write pemissions
  • 2 Solutions collect form web for “Access Docker features when using Vagrant”

    Try to specify “has_ssh” to true, and ask Vagrant to use port 22 instead of 2222:

    ENV["VAGRANT_DEFAULT_PROVIDER"] = "docker"
    
    Vagrant.configure("2") do |config|
      config.vm.provider "docker" do |d, o|
        d.image = "fgrehm/vagrant-ubuntu:precise"
        d.has_ssh = true
        o.ssh.port = 22
      end
    end
    

    Then use vagrant up; vagrant ssh to access it.

    Another option if you have same client version of docker at your host-host machine as docker server started inside boot2docker VM. In that case you can set

    export DOCKER_HOST=tcp://:4243 (or 2375 depending on docker version)
    

    and then access all docker features running local client:

    docker ps -a
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.