英文:
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
但是什么都没有发生
英文:
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
答案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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论