Multiple vhosts on one and the same docker container

Turns out this was an Apache configuration issue.

I needed to explicitly enable domain-named virtualhosts, like so:

NameVirtualHost *:80

This answer helped.

Docker had nothing to do with the matter.


The fab/centos does not exist in public docker hub, so not sure why you are experiencing the issue.

My recommendation would be to take a step back and try to make it work with a simple example.

docker search apache yields eboraas/apache as most starred image, so I'll use that one for the example.

In a test directory, use your sample:

File: httpd.conf

<VirtualHost *:80> # first host = default host
    DocumentRoot /var/www/html/default
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot /var/www/html/dummy
    ServerName dummy.dev
    ServerAdmin [email protected]
    ErrorLog logs/dummy.dev-error_log
    CustomLog logs/dummy.dev-access_log common
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot /var/www/html/tests
    ServerName tests.dev
    ServerAdmin [email protected]
    ErrorLog logs/tests.dev-error_log
    CustomLog logs/tests.dev-access_log common
</VirtualHost>

Then create the vhost websites & the logs directory.

mkdir -p logs; for i in default tests dummy; do mkdir -p $i; echo "hello $i" > $i/index.html; done

Finally, run docker.

docker run -it -v $(pwd):/var/www/html -v $(pwd)/httpd.conf:/etc/apache2/sites-available/000-default.conf -v $(pwd)/logs:/etc/apache2/logs -p 9090:80 --rm --name apache_c eboraas/apache

Note that I use basically the same volumes as you did in your docker-compose.yml, except that I use site-available instead of changing the httpd.conf.

To test, make sure you have tests.dev and dummy.dev in your /etc/hosts pointing at the right Docker IP and test:

$> curl dummy.dev:9090
hello dummy
$> curl tests.dev:9090
hello tests

From this point, build up on top of this by first trying the docker apache image that you are using, then try with your custom /etc/hosts file, then put it back in a docker-compose file