Been dealing with this problem for 2 days already, don't understand why it won't create the file. Cannot find any info on this online.
Task
Design an apache container that creates a custom index.html file with container's hostname in it (for load balancing testing) on startup.
Basically I need it to run 'uname -n > /var/www/html/index.html' on startup. But no matter what I do file is not created.
Tried
Running this script in Dockerfile's CMD/ENTRYPOINT:
#!/bin/bash apachectl -DFOREGROUND /bin/uname -n | tee /var/www/html/index.html and
#!/bin/bash apachectl -DFOREGROUND /bin/uname -n > /var/www/html/index.html Apache starts but file is not there.
But if I start container with just ENTRYPOINT and then attach to it and run the same script that was copied during build - it creates the file...
Tried keeping only ENTRYPOINT ["apachectl","-DFOREGROUND"] and running needed command with 'docker run ...', but then apache doesn't start and container exits right away.
I'm confused. Please, any help will be greatly appreciated.
51 Answer
apachectl -DFOREGROUND runs in the foreground. In other words, it blocks the progress of your entrypoint script until apachectl exits.
I'm no Apache expert, but I suspect the easiest solution is to switch the order of the commands - do the uname stuff before starting Apache.