I have a docker-compose.yml file, simplified below
slim-first:
image: slim-image
expose:
- 9191
slim-second:
image: slim-image
expose:
- 9192
The slim-image
image comes from a Dockerfile
that starts a service (using the PHP Slim framework) with the following command
#File: Dockerfile
# ...
CMD ["/usr/local/bin/php", "-S", "0.0.0.0:9191", "-t", "/slim/public"]
You may have already spotted the problem -- I need to provide PHP's built-in webserver with a port. However, I'm trying to start two services -- each available on a different port.
My Question: Is there a way for me, in my Dockerfile
to access the expose
d port values from my docker-composer.yml
file?
Or is the solution to duplicate the port number into an environment variable that the Dockerfile
can see.
Or is there some third path that would let me have the port value configured in one, and one place, only?
To clarify, I know I could do something like this
slim-second:
image: slim-image
expose:
- 9192
args:
- PORT=9192
...
ARG PORT=9191
CMD ["/usr/local/bin/php", "-S", "0.0.0.0:$PORT", "-t", "/slim/public"]
but I don't want to repeat the port twice in my docker-compose.yml file.