I'm trying to build a docker image for local PHP development based on openSUSE, PHP7 and Apache 2.4. Apache should resolve...
http://localhost -> /srv/www/htdocs (openSUSE standard)
http://myapp -> /srv/www/myapp/public
...
(http://myapp.localhost, http://myapp.dev etc. would also be ok, if that's easier to achieve.)
In order to configure the vhosts, I added /etc/apache2/vhosts.d/myapp.conf with this content:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /srv/www/htdocs
</VirtualHost>
<VirtualHost *:80>
ServerName myapp
DocumentRoot "/srv/www/myapp/public"
<Directory "/srv/www/myapp/public">
AllowOverride None
</Directory>
</VirtualHost>
This file seems to be used by Apache. apachectl -S leads to this output:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server localhost (/etc/apache2/vhosts.d/myapp.conf:2)
port 80 namevhost localhost (/etc/apache2/vhosts.d/myapp.conf:2)
port 80 namevhost myapp (/etc/apache2/vhosts.d/myapp.conf:10)
ServerRoot: "/srv/www"
Main DocumentRoot: "/srv/www/htdocs"
Main ErrorLog: "/var/log/apache2/error_log"
Mutex ssl-stapling-refresh: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/run/" mechanism=default
Mutex mpm-accept: using_defaults
PidFile: "/var/run/httpd.pid"
Define: SYSCONFIG
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="wwwrun" id=30
Group: name="www" id=8
Now, localhost is resolved correctly and myapp is not. Chrome says "ERR_NAME_NOT_RESOLVED".
I guess, this is because there is no entry in /etc/hosts for myapp. However, as far as I understand, docker does not allow /etc/hosts to be modified. I tried to do this with sed in my Dockerfile:
RUN sed -i 's/^127.0.0.1.*$/127.0.0.1 localhost myapp/g' /etc/hosts
in order to add the mapping myapp -> 127.0.0.1 to /etc/hosts. However, docker build says
sed: cannot rename /etc/sedLXNJtt: Device or resource busy
My question is thus: How do I tell my container to resolve myapp correctly?