Will Wang
Will Wang

Reputation: 197

Docker can't connect containers

So I want to run a redis container and a jupyter container that makes requests to the redis server and plots that data. I run

sudo docker run --name=redis -p 6379:6379 -d redis
sudo docker run -d --name=jupyter -p 8888:8888 hantaowang/visualizer start-notebook.sh --NotebookApp.token=''

But the notebook will not run. It says ConnectionError: Error 111 connecting to 127.0.0.1:6379. Connection refused. Can anyone help? Thanks in advance.

EDIT: I use my own dockerfile instead.

FROM jupyter/scipy-notebook
ADD visualizer.ipynb visualizer.ipynb
RUN pip3 install redis

Upvotes: 0

Views: 168

Answers (2)

BMW
BMW

Reputation: 45243

You need link the redis container to jupyter container with option --link.

Go through the README of official redis container.

https://hub.docker.com/_/redis/

You should be fine to link it with below sample:

$ docker run --name some-app --link some-redis:redis -d application-that-uses-redis

So your command should be changed to

# No need expose the port 6379 now, because you link redis container to the other directly
$ sudo docker run --name=redis -d redis

$ sudo docker run -d --name=jupyter --link redis:redis -p 8888:8888 jupyter/scipy-notebook start-notebook.sh --NotebookApp.token=''

Upvotes: 1

Derick Bailey
Derick Bailey

Reputation: 72868

127.0.0.1 always points to the "computer" (virtual or otherwise) that made the request. In this case 127.0.0.1:6379 points to the jupyter container that is making the request.

use resis:6379

when you name a container, docker adds that name to the private docker network

Upvotes: 0

Related Questions