How to access Docker container's web server fr

2019-03-08 03:24发布

I'm running under boot2docker 1.3.1.

I have a Docker container running a web server via uwsgi --http :8080.

If I attach to the container I can browse the web site using lynx http://127.0.0.1:8080 so I know the server is working.

I ran my container with:

$ docker run -itP --expose 8080 uwsgi_app:0.2

It has the following details:

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                     NAMES
5248ad86596d        uwsgi_app:0.2     "bash"              11 minutes ago      Up 11 minutes       0.0.0.0:49159->8080/tcp   cocky_hypatia
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' 5248ad86596d
172.17.0.107

I thought I could access that web site from my host by going to http://172.17.0.107:49159.

This does not work. I just see 'connecting...' in Chrome, getting nowhere.

What am I doing wrong?

8条回答
冷血范
2楼-- · 2019-03-08 03:45

You could use boot2docker port mapping option -L, as described here.

So, in your case it would be

boot2docker ssh -L 0.0.0.0:8080:localhost:8080

and then

docker run -it -p 8080:8080 uwsgi_app:0.2

That way, you do not have to use boot2docker's IP address: you can use localhost or your own IP address (and your docker container can be accessed from outside).

查看更多
够拽才男人
3楼-- · 2019-03-08 03:50

Had the same issue and in my case i was using AWS EC2 instance. I was trying with the container IP which did not work. Then I used the actual public IP of the AWS host as the IP, which worked.

查看更多
登录 后发表回答