T
T
topuserman2021-11-05 13:41:55
Docker
topuserman, 2021-11-05 13:41:55

Dockerfile: why do you need EXPOS or VOLUME if you still need to forward ip or mount when starting a container?

I'm studying docker, and I ran into two questions:

1. The first question follows from the title of the question: why do we need EXPOS or VOLUME, if when starting the container you still need to forward ip or make a mount?
For example (in the example I omitted unnecessary moments):

FROM ubuntu:latest
RUN apt update && apt install -y nginx && apt install -y php-fpm
EXPOSE 80

why write EXPOSE 80 if ip is still not forwarded, and you will need to specify -p 80:80 when starting the container ?

And the same with VOLUME.
Perhaps they have a different meaning depending on the context of use,
but I did not understand this.

2. The second question: if I run several containers, do I understand correctly that they can easily communicate via localhost and do I need to forward some ports for this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2021-11-05
@Lynn

https://docs.docker.com/engine/reference/builder/

The EXPOSEinstruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published.

This is a help to your future container user so that he knows which ports to open. It is not necessary to use.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question