docker 容器端口访问不到,无法连接到应用程序正在侦听的docker容器端口

I want to run Jenkins, but to demonstrate the problem, I'm running a netcat server container in Ubuntu 15.10:

Docker version 1.6.2, build 7c8fca2

Here's my Dockerfile:

FROM ubuntu

CMD while true; do echo 'HTTP/1.1 200 OK\r\n\r\nHello world' | nc -l 8080; done

When run on the host, this one-liner will return HTTP 200 responses.

Now, on the container. Ran docker build -t mydoc .. Ran docker run -it --expose 8080 -p 8080:8080 mydoc. In another terminal, tried to curl it: curl -D - -o - http://127.0.0.1:8080.

It just blocks with no response.

Some possibly relevant info:

>docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

1acc13bb3384 mydoc:latest "/bin/sh -c 'while t 48 seconds ago Up 47 seconds 0.0.0.0:8080->8080/tcp goofy_darwin

and

>netstat -ant | grep 8080

tcp 0 1 10.0.2.15:34512 172.17.0.25:8080 SYN_SENT

tcp 0 0 127.0.0.1:33276 127.0.0.1:8080 ESTABLISHED

tcp6 0 0 :::8080 :::* LISTEN

tcp6 78 0 127.0.0.1:8080 127.0.0.1:33276 ESTABLISHED

Note the SYN_SENT. That's as far as it gets.

解决方案

The Linux service status showed as:

● docker.service - Docker Application Container Engine

Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)

Active: active (running) since Mon 2016-03-07 13:39:44 CST; 2min 24s ago

Docs: http://docs.docker.com

Main PID: 672 (docker)

Memory: 11.2M

CPU: 62ms

CGroup: /system.slice/docker.service

└─672 /usr/bin/docker -d -H fd://

This fixed the issue:

service docker restart

I don't know why. Now the service responds:

>curl -D - http://127.0.0.1:8080

HTTP/1.1 200 OK

Hello world

Also, the option --expose 8080 was not necessary for this to work.

EDIT:

After getting 1.6.2 to work, I upgraded to 1.10.2 and haven't seen this problem yet. I suspect some kind of race condition on host startup, but can't say for sure. Maybe the docker service script needs a Required-Start: $network or something.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值