简体   繁体   中英

Use multiple ports in Docker multistage build

I am using MultiStage in docker for performing tests tasks. The base image is Selenium which exposes port 4444 and the staged image is nginx for other operations.

The nginx has port 80 exposed. If I have to expose both ports, only the port80 is exposed, and not 4444 when using

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

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 .

It DOES contain everything from the image specified in the last FROM instruction and results of all the commands below.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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