I have 3 docker containers (FrontEnd, Database, and ApachePhp) within the same Docker network. ApachePhp will be a web server (Apache + PHP) that I need to make visible only through the FrontEnd i.e. only requests to ApachePhp should be accepted through the FrontEnd. I have the following apache config file:

<VirtualHost *:80>
  ServerAdmin me@mydomain.com
  DocumentRoot /var/www/site

  <Directory /var/www/site/>
          Require ip FrontEnd

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined


Is this the correct way to use Require and obtain the desired result?


You don't need to solve this in your apache configuration. As long as you do not publish the port, docker will not configure a forwarding rule or proxy to send external traffic to your container. There's no need to expose the port either in docker (that's just for documentation). The only steps required to communicate between docker containers are:

  1. Listen inside your application on all interfaces (I believe you've done that with the *:80).
  2. Connect the containers to a common docker network. This happens automatically when you deploy with a single docker-compose.yml.
  3. From the client, use docker's built in DNS for the hostname and connect to the container port. Docker's DNS will resolve the container name, and with compose files the service name can also be resolved. So if your container/service name is phpbackend, you would connect from the frontend to phpbackend:80.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.