What is the simplest way to install Redis in Docker+Vagrant

docker, redis, vagrant

Solution

Your Vagrantfile is correct.

This seems to be an issue with the `chef/centos-6.5` box.

On this box, you have to update `device-mapper-libs` first.

I had success with this Vagrantfile:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "chef/centos-6.5"

  config.vm.provision "shell",
    inline: "yum update -y device-mapper-libs"

  config.vm.provision "docker" do |docker|
    docker.run "redis"
  end
end

Inside the VM:

[vagrant@localhost ~]$ docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES
7d55185f859c        redis:2             "/entrypoint.sh redi   10 seconds ago      Up 9 seconds        6379/tcp            redis

Problem

I would like to have a Docker container running Redis, inside a Vagrant VM. I'd like things to be as simple as they can possibly be, so minimal configuration. A little bit of research shows: - Vagrant provides a Docker provisioner - Docker provides a trusted Dockerfile for Redis So the setup should be really straight forward, I expected to just have to connect the dots. So I came up with this `Vagrantfile`: ``` VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "chef/centos-6.5" config.vm.provision "docker" do |docker| docker.run "dockerfile/redis" end end ``` Looks simple - good. Now when I run `vagrant up` I would expect: - The VM starts up. - Docker gets installed. - The Docker daemon `dockerd` is started. - The Docker container for Redis `dockerfile/redis` is downloaded and installed. - The container is started. All seems to work except step 3, since with this `Vagrantfile` I get: ``` ==> default: Verifying vmnet devices are healthy... ==> default: Preparing network adapters... ==> default: Starting the VMware VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 192.168.249.190:22 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection refused. Retrying... ==> default: Machine booted and ready! ==> default: Forwarding ports... default: -- 22 => 2222 ==> default: Configuring network adapters within the VM... ==> default: Waiting for HGFS kernel module to load... ==> default: Enabling and configuring shared folders... default: -- /Users/ernst/nikon/nikon-elk-vm2: /vagrant ==> default: Running provisioner: docker... default: Installing Docker (latest) onto machine... default: Configuring Docker to autostart containers... ==> default: Starting Docker containers... ==> default: -- Container: dockerfile/redis The following SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed! rm -f /var/lib/vagrant/cids/cc3cfcdebad9167099d85261c6311a0011838655 docker run --cidfile=/var/lib/vagrant/cids/cc3cfcdebad9167099d85261c6311a0011838655 -d --name dockerfile-redis dockerfile/redis Stdout from the command: Stderr from the command: 2014/11/26 12:38:40 Cannot connect to the Docker daemon. Is 'docker -d' running on this host? ``` I could obviously revert to using the `shell` provisioner, but I would love to keep my `Vagrantfile` simple and use the `docker` provisioner that Vagrant offers. So what am I missing?

Original source