简体   繁体   English

在 Docker 多阶段构建中使用多个端口

[英]Use multiple ports in Docker multistage build

I am using MultiStage in docker for performing tests tasks.我在 docker 中使用 MultiStage 来执行测试任务。 The base image is Selenium which exposes port 4444 and the staged image is nginx for other operations.基础镜像为 Selenium,暴露端口 4444,暂存镜像为 nginx 用于其他操作。

The nginx has port 80 exposed. nginx 暴露了端口 80。 If I have to expose both ports, only the port80 is exposed, and not 4444 when using如果我必须公开两个端口,则只有端口 80 被公开,而不是 4444 使用时

docker run -p 80:80 -p 4444:4444 someimage:2

Dockerfile: Dockerfile:

FROM selenium/standalone-firefox AS base
RUN python3 try.py

FROM nginx:alpine
COPY --from=base /report.html /usr/share/nginx/html

You misunderstand how the multistage build works.您误解了多阶段构建的工作原理。

Your final image DOES NOT contain everything from every image you specified in your Dockerfile .您的最终图像包含您在Dockerfile中指定的每张图像的所有内容。

It DOES contain everything from the image specified in the last FROM instruction and results of all the commands below.确实包含最后一个FROM指令中指定的图像的所有内容以及以下所有命令的结果。

In you case it contains everything from image nginx:latest and file report.html copied from previous build stage - which means that when you use it to run a container there is nothing listening on port 4444, so exposing it is meaningless.在你的情况下,它包含从图像nginx:latest和文件report.html复制自上一个构建阶段的所有内容 - 这意味着当你使用它来运行容器时,没有任何东西在端口 4444 上侦听,所以暴露它是没有意义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM