Docker Run without “docker run”

So there was this one question on Stackoverflow in which the OP was linking an .htaccess tester for Mod-Rewrite-Rules. Despite this being all fine I was asking myself what about really(tm) testing this?

So I remembered the rewrite-log from the days ago and thought: Why not just fire up a docker container, do the setup for testing rewrites by turning the logs to screaming and give it a drive.

But all the setup.

So I had an idea: What about you put the whole example into the Dockerfile? It has the RUN directive, so the moment the image builds it is actually executing it.

Having it exit non-zero even prevents of storing the image locally.

Ah yeah, and why actually write a Dockerfile even.

<<'EOD' docker build –rm –tag rewrite-tester –no-cache –
FROM httpd:alpine
RUN set -e \
; sed -i -e 's/^#LoadModule rewrite_module/LoadModule rewrite_module/' \
-e 's/^LogLevel .*$/LogLevel debug rewrite:trace8/' \
-e '\|<Directory "/usr/local/apache2/htdocs">|,\ </Directory> s/^ AllowOverride .*$/ AllowOverride All/' \
/usr/local/apache2/conf/httpd.conf \
; echo -e ' \n\
RewriteEngine On \n\
RewriteBase / \n\
RewriteCond %{REQUEST_URI} \.(gif|jpg|jpeg|png)$ \n\
RewriteRule ^(.*)$ $1?i=jplx [DPI,QSA] \n\
RewriteCond %{REQUEST_URI} !^/sites/default/files/js/ \n\
RewriteCond %{REQUEST_URI} !^/sites/default/files/css/ \n\
RewriteRule ^sites/default/files/(.*)$ index.php?q=system/files/$1 [END,QSA,R] \n\
' | tee /usr/local/apache2/htdocs/.htaccess \
; httpd-foreground & sleep 1 \
; apk add curl \
; curl -I '; \
; exit 123


This also clearly highlights a missing feature in docker: no support for here-doc strings in the Dockerfile since 2013, echo -e to the rescue (but it’s cumbersome).

This entry was posted in Hakre's Tips, Patched, Pressed, Professional Webdevelopers At Work, Scripts, Surviving the Internet, Tools, Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.