Vagrant provision with Docker

I want to run a docker image on Vagrant machine.
My Vagrantfile is straingforward:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.synced_folder "./project/", "/project/"
  config.vm.network "forwarded_port", guest: 8000, host: 8000
  config.vm.network :public_network, bridge: 'eth0'

  config.vm.provision "docker" do |d|
    d.run 'ldap', image: '10.5.6.19:5000/ldap'
  end

end

I have this image on my machine:

  • How to have login and access settings with a docker image registry
  • Golang Mac OSX build for Docker machine
  • Custom DOCKER_HOST in Elastic Beanstalk Docker environment
  • Running Redis with Docker (performance issue)
  • Docker won't change VHD location
  • Docker as provider for Vagrant
  • >sudo docker images 
    
    REPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    
    10.5.6.19:5000/ldap   latest              ef7f4dcecd65        3 months ago        930.8 MB
    

    but when I try to provision a machine with vagrant provision. I achieve an error:
    Stdout from the command:

    Stderr from the command:

    stdin: is not a tty
    Unable to find image '10.5.6.19:5000/ldap:latest' locally
    time="2014-12-30T13:50:37Z" level="fatal" msg="Error: Invalid registry endpoint https://10.14.6.19:5000/v1/: Get https://10.14.6.19:5000/v1/_ping: dial tcp 10.14.6.19:5000: i/o timeout. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 10.14.6.19:5000` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/10.14.6.19:5000/ca.crt"
    

    I think this happens because I should use some kind of registry for images. Is there a way to use local images for vagrant provisioning?

  • Configure PM2 module with linked docker container
  • Running and debugging an ASP.NET Core RC2 application in Docker
  • Converting an ElasticBeanstalk environment to a Docker container
  • docker COPY without save point
  • how to run an image of software on other node?
  • Importing self-signed cert into Docker's JRE cacert is not recognized by the service
  • 2 Solutions collect form web for “Vagrant provision with Docker”

    You need to add the following in /etc/default/docker:

    DOCKER_OPTS="--insecure-registry 10.14.6.19:5000"
    

    On a side note, this goes in EXTRA_ARGS in /var/lib/boot2docker/profile in case you were using boot2docker.

    There are a few options to choose from to fix this:

    1. Once the VM starts, manually add that line. Then restart the VM.
    2. Build a box that already has the above config set and use that in your Vagrantfile
    3. Use a shell provisioner set up that config.

    To use option 3, include this before the docker provisioner:

      config.vm.provision "shell",
        inline: <<-EOS
          echo 'DOCKER_OPTS="--insecure-registry 10.14.6.19:5000 ${DOCKER_OPTS}"' \
            >> /etc/default/docker
      EOS
    

    After this if you execute vagrant up (or vagrant reload --provision in case the vm is already running), you’ll be able to run your image without any problems.

    Provisioning with docker means that vagrant will manage a VM by provisioning it with docker and commands you supply. This will be a different machine than your host with different docker and independent pull of images. The way to get your image inside the vagrant would be to perform the same actions you did on your host to get that image in the first place, or to share the image via the docker hub.

    If you can run docker natively (meaning you are on linux), you might alternatively consider using docker as vagrant provider. I guess in this case you will use the docker of the host and hence will get access to the images of it.

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