大网数据广告活动
服务器运维问答

Howto expose port in docker container

· 52CE 我爱测

I’ve run a web service in a docker container on a custom port (8080). Here, I’m trying to run a container, exposing the relevant container’s port (as seen here ), but the no avail. docker run -p 127.0.0.1:8080:8080 beatthemarket …

问题原文

原帖链接 · Frye · CC BY-SA 3.0

I’ve run a web service in a docker container on a custom port (8080). Here, I’m trying to run a container, exposing the relevant container’s port (as seen here), but the no avail.

docker run -p 127.0.0.1:8080:8080 beatthemarket run wait

But I can’t seem to reach that web service endpoint.

i) Am I correctly exposing the container's port? ii) How can troubleshoot if it's the port that's unavailable, or if my web service just isn't getting called (it would be nice to be able to shell into the container and just curl the endpoint).

My Dockerfile can be seen here. And I’m using Adzerk’s boot-clj base image.

Actually running docker, each time retrieves a bunch of jars. Then boot blocks (the wait task), which is what I want (a web server will be handling web requests). And this is where I’m lost. Boot, in docker, blocks as I’ve asked it to. But I can’t seem to get the basic Hello World message that a root URI should return.

$ docker run -p 127.0.0.1:8080:8080 beatthemarket run wait
Downloading https://github.com/boot-clj/boot/releases/download/2.5.5/boot.jar...
Retrieving dynapath-0.2.3.jar from https://clojars.org/repo/
Retrieving pod-2.5.5.jar from https://clojars.org/repo/
Retrieving shimdandy-impl-1.2.0.jar from https://repo1.maven.org/maven2/
Retrieving core-2.5.5.jar from https://clojars.org/repo/
...
Implicit target dir is deprecated, please use the target task instead.
Set BOOT_EMIT_TARGET=no to disable implicit target dir.

The Chrome, curl and wget all say that the connection is refused.

$ curl http://127.0.0.1:8080/
curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection refused

$ wget http://127.0.0.1:8080/
--2016-04-21 20:07:32--  http://127.0.0.1:8080/
Connecting to 127.0.0.1:8080... failed: Connection refused. 

已采纳解答

原帖链接 · Joe Doyle · CC BY-SA 3.0

You need to add the EXPOSE statement to your Dockerfile for port 8080.

Here's the reference from Docker: https://docs.docker.com/engine/reference/builder/#expose

Your final Dockerfile should look like this:

FROM adzerk/boot-clj

EXPOSE 8080

WORKDIR /app
COPY . /app

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-04-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。