通过容器IP访问Docker不起作用,但可以通过Localhost访问
我一直在学习Docker,我了解到的一件事是,如果端口在容器中公开并且应用程序在该端口正在运行,那么您可以使用http:// container_ip:port
port 访问它。已经进行了测试,并且总是有效的。
但是今天,在使用Angular应用程序执行此操作的同时,我发现我无法访问URL,并且不会返回任何内容。 神奇地我想到击中http:// localhost:port
and and ant ant ant and ant and ant and and other,这是怎么可能的,为什么它甚至首先发生?
dockerfile
# Stage 1
FROM node as build-step
RUN mkdir -p /app
WORKDIR /app
COPY package.*json /app
RUN npm install
COPY . /app
# RUN npm install -g ts-node
RUN npm run build
# Stage 2
FROM nginx
EXPOSE 80
COPY --from=build-step /app/dist/test-app /usr/share/nginx/html
任何帮助都将受到赞赏。
I have been learning docker and one thing I learned is that if a port is exposed in a container and an application is running at that port then you can access it using http://container_IP:port
which I have tested and it always works.
But today while doing the same with an Angular app, I found that I can't access the URL and it does not return anything.
Magically I thought of hitting http://localhost:port
and it worked, how is this possible and why did it even happen in the first place?
Dockerfile
# Stage 1
FROM node as build-step
RUN mkdir -p /app
WORKDIR /app
COPY package.*json /app
RUN npm install
COPY . /app
# RUN npm install -g ts-node
RUN npm run build
# Stage 2
FROM nginx
EXPOSE 80
COPY --from=build-step /app/dist/test-app /usr/share/nginx/html
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该使用容器IP地址
这就是为什么您要公开
端口
,因为要映射container
端口到localhost
portYou shouldn't use container IP address
that's why you are exposing the
port
because you want to mapcontainer
port tolocalhost
port