Search code examples
pythondockertornado

Connect to Tornado app in Docker


In Dockerfile I use:

EXPOSE 8888

So, I run the container:

docker run --name some-app --link some-redis:redis -d app

In output I have this string:

c980349b5b2120064fc197b00a1aaf94aa16c788b66cb148da7826bb5488d0db

Then I want to know the ip, that I can connect from browser:

docker inspect --format '{{ .NetworkSettings.IPAddress }}' c980349b
5b2120064fc197b00a1aaf94aa16c788b66cb148da7826bb5488d0db

It returns 172.17.0.20

I go to web-brouser and on page http://172.17.0.20:8888, but I have in Chrome

ERR_CONNECTION_TIMED_OUT

Whats the problem and how to fix that?

Thanks!

UPDATE

Dockerfile:

FROM python:3.4.3-slim
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY app.py /usr/src/app/
COPY requirements.txt /usr/src/app/
RUN pip install -r requirements.txt
CMD [ "python", "./app.py" ]
EXPOSE 8888

When I use:

docker exec -it some-app bash
netstat -tulnp | grep 8888

It returned:

bash: netstat: command not found

And

docker logs some-app

Returns nothing


Solution

  • I would check twice the image because it seems that the container has not any process listening on port 8888. To debug the issue you can run a shell session inside the container and check the if the process is listening, check the container log or any file inside if there is any log you can check,... I.E.:

       $ sudo docker logs some-app (check container log)
       $ sudo docker exec -it some-app bash  (run an interactive shell)
       # netstat -tulnp | grep 8888   (check if any process is listening)
    

    If you don not see the problem I would ask you to post your app Dockerfile and Apart from that you don't need to use EXPOSE 8888 in your Dockerfile if you use the container ip to access your service. EXPOSE is used to enable those port to be published to random ports of the host machine, when the container is run with -P option.