Troubles accessing redis container from a VBox VM (same host)

Hi there,

I started to learn Docker a few days ago, and I’m encountering an issue which looks like a networking issue.
I have atm a dev environment provided by Vagrant and orchestrated by Puppet, and I what I want is to switch from Puppet code to Docker containers. All the containers must be running within the host computer, not in the VM.

What I’m trying to do, to begin with, is to migrate the redis-server in a container.
To make some tests before integrating a more complex Dockerfile is a simple docker run -d --name redis -p 6379:6379 redis

It creates the container, running and accessible from the host with a redis-cli ping. The redis default image contains EXPOSE 6379.
The network used is, by default, bridge mode docker0 172.17.0.0/16.

The issue is : I can’t access my redis from my VM. redis-cli -h 172.17.0.2 is returning “No route to host”, and redis-cli ping “Cannot connect to 127.0.0.1” or something.

In my Vagrantfile, I got the forwarded ports 6379 enabled, first adapter is NAT and the second is host-only (network 192.168.33.0/24, I have my dev box and my elasticsearchbox on it)

I looked into iptables but Docker seems to “allow anywhere” by default. I tried to add ip routes too, without any success. Bridge mode on VBox instead of host-only doesn’t seems to work, but I may be doing something wrong.

I’m able to ping 172.17.0.1 from my VM (docker0 interface from the host computer), but I can’t reach 172.17.0.2 (container’s internal IP)

I also have a .env file in my laravel folder, specifying REDIS_HOST and REDIS_PORT, doesn’t work too with 172.17.0.2:6379.

I made a quick draw of what I think my private network looks like, more or less : https://imgur.com/a/coDdr

I think I’m missing something, it’s maybe obvious for someone ? I could need help there :slight_smile:

Thanks for your time

These Docker-internal IP addresses are basically totally useless. Don’t try to use them.

Redis will be accessible on the host IP address on port 6379. (It’s the same behavior as Vagrant’s forwarded ports.) It doesn’t look like there’s a generic way to find this.

At a networking level, this problem is very very similar to trying to migrate services from one Vagrant box to another, it looks like…a quick Google search seems to come up with the same basic answer as in Docker land (you need the host’s IP address and there’s not a universal constant for it).

192.168.33.1 might work to reach the host from the Vagrant box. I’ve seen 10.0.2.2 cited as a common value as well (it shows up in your diagram).

I think the two arrows at the bottom should be pointing in the same direction. If you have a Vagrant forwarded port saying port 2201 on the host forwards to port 6379 in the VM, that’s a direction for the host to access Redis in the VM, not the other way.

1 Like

Problem solved :slight_smile: Thank you