First, take a look in this that talks a little more about the differences of publishing/displaying doors.
Would it be on Dockerfile? This option is mandatory if we want to expose the doors?
Use the EXPOSE
in the definition of the images, in this case, may not be necessary, but it is always good practice, since it works as a kind of documentation. When using EXPOSE
you tell the image user which ports and in which protocol can be exposed to the host - or other Networks - safely. As stated, its use is not required.
Or is it when loading the image? If this option is used the previous option would be required?
When using the post/display in creating and/or running containers it will not be necessary to EXPOSE
explicit. When using port publishing host in the creation of a container or execution of an existing container, if you have not specified with the EXPOSE
which doors intentionally can and/or must be exposed, the Docker implicitly will do the EXPOSE
- it does not alter the image, however.
My question is: what is the correct way to expose these doors, beyond the 80?
In short, there is no "right" way, you can combine the ways or use them separately, it will depend on how the containers run - as for Networks, mainly -, of how structured its containers, etc.
In your case, however, you need certain doors to be accessible on host, which is where your IDE is running. In this case it is recommended to use both EXPOSE
, both for its use as documentation and will give greater flexibility to a third-party user of its image, and it is necessary that the ports are published for access by host, then you’ll need the -p/
--Publish/
-P/--publish-all
. Even so you may not need to publish all host, if it is not mandatory that host have access to all the mentioned doors - such as, for example, 6379 be accessed only by another container on the same network.
P.S.: in your dockerfile you can inform the doors in just one instruction, such as EXPOSE 80 6379 9000
. This will create a single layer, facilitates image inspection in most cases.
You are treating container as VM, and this is an error. Whoever answers for port 80, should not be in the same container that redis is in. This container should most likely be dismembered into 3 containers, orchestrated in a Docker-Compose. You at least reuse an image (redis), if you don’t reuse the other.
– Luiz Carlos Faria
As for the redis I agree with you. We should use 2 containers - 1 for each service. But it was a decision of the company to keep REDIS in the same container. What I don’t understand is how much to the third container you mentioned. You mean I should use a container for Xdebug?
– zwitterion
For not knowing Xdebug I was not so emphatic to say that there are certainly 3. Now that I saw what it is, this should be next to PHP yes.
– Luiz Carlos Faria