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:

  • What's the diff between Empty and No Value for Docker Volumes From?
  • Docker integration test with static data at launch
  • Window version of Docker not able to mount local directory to ubuntu image on container?
  • What is the tool to deploy dockerized apps?
  • Is alpine distribution food for big scale apps?
  • Basic Docker container reports runlevel unknown
  • >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?

  • Docker behind proxy that changes ssl certificate
  • Run Go script inside Docker Container or cron job?
  • 'su' command in Docker returns 'must be run from terminal'
  • Way to increase Boot2Docker volume size or alternative to install docker images locally
  • convert a Windows solution into windows docker containers
  • When does Docker image cache invalidation occur?
  • 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.