Dockerfile 暴露 80 端口

huangapple go评论85阅读模式
英文:

Dockerfile expose 80 port

问题

我正在尝试创建一个带有go mod和1.18的简单Docker容器。
我的应用程序在8080端口运行,但我想在80端口运行。

Dockerfile

FROM golang:1.18

WORKDIR /usr/src/app

# 预先复制/缓存go.mod以预先下载依赖项,并仅在后续构建中重新下载更改的依赖项
COPY go.mod go.sum ./
RUN go mod download && go mod verify

COPY . .
RUN go build -o server

CMD ["./server"]

然后我运行docker build:

docker build -t go-k8s . 

然后运行docker run:

docker run --rm -p 8080:8080 go-k8s:latest

但是什么都没有发生 Dockerfile 暴露 80 端口

英文:

I am trying to create a simple docker container with go mod and 1.18.
my app runs in 8080 port but i wanna run in :80 port

Dockerfile

FROM golang:1.18

WORKDIR /usr/src/app

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN go mod download && go mod verify

COPY . .
RUN go build -o server

CMD [ "./server" ]

so i run docker build:

docker build -t go-k8s . 

and docker run

docker run --rm -p 8080:8080 go-k8s:latest

And nothing happens Dockerfile 暴露 80 端口

答案1

得分: 1

如larsks所说,您需要使用80:8080语法将外部端口80绑定到内部端口8080

另外要考虑的是确保您的应用程序在开发环境中监听所有接口。

这个问题似乎至少与您的问题有些关联。

英文:

As larsks says, you need to bind from the external port 80 to the internal port 8080 using the 80:8080 syntax.

Something else to consider is making sure that your app is listening on all interfaces in your development environment.

This question seems at least vaguely related to yours

huangapple
  • 本文由 发表于 2022年6月9日 09:41:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/72553847.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定