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 assign a group of logical Linux interfaces to a Docker container?
  • How to claim free space generated by deleting docker images in Mac
  • Docker Compose Overriding
  • Running python program on docker
  • Using ENV variables in daemonized Docker running RStudio
  • Github repo with more than one python packages
  • >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 - Handling multiple services in a single container
  • Docker image location
  • What are default credentials for docker cloud Ubuntu node?
  • Docker: skygear server not starting, connection refused
  • Docker: Can a secret created and deleted in a single RUN command be recovered from the resulting image?
  • backports/lzma/_lzmamodule.c:115:18: fatal error: lzma.h: No such file or directory
  • 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.