Chrome's ERR_CONTENT_DECODING_FAILED when compression="on" with tomcat:7-jreX-alpine
When enable compression on Tomcat (compression="on" parameter on server.xml), I get ERR_CONTENT_DECODING_FAILED when trying to access Tomcat Manager App (Tomcat /manager/html web app).
To reproduce this error, follow steps below:
- Create a
Dockerfilewith the following content:
# Could be tomcat:7-jre7-alpine also
FROM tomcat:7-jre8-alpine
# Set Manager user/password as tomcat/tomcat on tomcat-users.xml
RUN sed -i 's/<\/tomcat-users>/<user password="tomcat" roles="admin-gui,manager-script,admin,manager-gui" username="tomcat"\/><\/tomcat-users>/' conf/tomcat-users.xml
# Set compression="ON" on server.xml
RUN sed -i 's/\(<Connector port="8080" protocol="HTTP\/1.1"\)/\1 compression="on" compressionMinSize="256" /' conf/server.xml
- Build the image:
docker build -t tomcat7-alpine-img .
- Execute the container:
docker run -d -p 8080:8080 --name tomcat7-alpine tomcat7-alpine-img
-
Open Tomcat's Manager web app with your favorite browser (http://localhost:8080/manager/html) and enter tomcat/tomcat as user/password
-
You will get the following error page:

With Firefox I get a similar error. If I disable compression, everything works fine.
Anything in the container logs when the failure occurs? Perhaps we're simply missing a package used for decompression. :speak_no_evil:
No, there is nothing in log files, at least not in catalina.log: tomcat7-alpine-catalina.zip
But now, I did the same test with the Debian based image (tomcat:7-jre8), with compression enabled and the problem did not ocurr (Dockerfile below)
FROM tomcat:7-jre8
# Set Manager's user/password as tomcat/tomcat on tomcat-users.xml file
RUN sed -i 's/<\/tomcat-users>/<user password="tomcat" roles="admin-gui,manager-script,admin,manager-gui" username="tomcat"\/><\/tomcat-users>/' conf/tomcat-users.xml
# Enabling compression on server.xml file
RUN sed -i 's/\(<Connector port="8080" protocol="HTTP\/1.1"\)/\1 compression="on" compressionMinSize="256" /' conf/server.xml
With tomcat:8-jre8-alpine everything works fine also (Dockerfile below)
FROM tomcat:8-jre8-alpine
# Removing Manager's access restriction on Manager's context.xml file
RUN sed -i 's/\(<Valve.*\)//' webapps/manager/META-INF/context.xml
RUN sed -i 's/\(allow.*\)//' webapps/manager/META-INF/context.xml
RUN sed -i 's/\(<Manager.*\)//' webapps/manager/META-INF/context.xml
# Set Manager user/password as tomcat/tomcat on tomcat-users.xml file
RUN sed -i 's/<\/tomcat-users>/<user password="tomcat" roles="admin-gui,manager-script,admin,manager-gui" username="tomcat"\/><\/tomcat-users>/' conf/tomcat-users.xml
# Enabling compression on server.xml file
RUN sed -i 's/\(<Connector port="8080" protocol="HTTP\/1.1"\)/\1 compression="on" compressionMinSize="256" /' conf/server.xml
The problematic combination seems to be: Tomcat 7 + OpenJDK 7/8 + Linux Alpine Image
Do you guys (@tianon ?) have any clues, so I can try to fix it myself? Where do I start?
What request mime type is causing issues for you? I'm getting errors on any application/json response over https. Everything else seems ok. I've just removed JSON from compressableMimeType and haven't had an issue.
The page from my first post above (Tomcat Manager) is text/html and it is broken with compression="on".
I did another test with ajax requests (Primefaces Showcase), returning text/xml, and it is also broken (screen below).

I am seeing the same issue. tomcat:7.0-jre8-alpine. A 'curl' to a compressible url results in:
Server: Apache-Coyote/1.1
Content-Type: application/xml;charset=UTF-8
Transfer-Encoding: chunked
Content-Encoding: gzip
Vary: Accept-Encoding
Date: Tue, 03 Oct 2017 17:54:57 GMT
followed by no output.
The log output is:
time="2017-10-03T17:55:42Z" level=info msg=" INFO: 172.17.0.1 - - [03/Oct/2017:17:55:42 +0000] "GET /SNIP HTTP/1.1" 200 4705"
No other log output.
The same query uncompressed results in:
time="2017-10-03T17:56:36Z" level=info msg="g INFO: 172.17.0.1 - - [03/Oct/2017:17:56:36 +0000] "GET /SNIP HTTP/1.1" 200 40346"
with headers of:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/xml;charset=UTF-8
Transfer-Encoding: chunked
Vary: Accept-Encoding
Date: Tue, 03 Oct 2017 17:58:39 GMT
followed by the full expected output.
When I use the GZIP program on the resulting uncompressed output, it comes down to 5268 bytes which is similar to the byte count reported by the compressed curl access log.
(arrived from google)
just ran into this issue, which appeared after an openjdk upgrade
specifically:
- did not work:
8.152.16 - worked:
8.131.11
maybe it's related
For what it's worth; we ran into this issue with a non containerized Tomcat instance and with Oracle JDK. For us, the issue seemed to be triggered by a JDK upgrade to 8.152, too. Toggling compression off seems to be a viable workaround.
I know this "me too" message doesn't help that much, however, maybe it will enable a future person to zero in on the cause with all these findings lying around.
Is it JDK bug? https://bugs.openjdk.java.net/browse/JDK-8189789
Thanks for sharing @kall. That's the real cause, as @femnad has already suspected.
I'll try to build a Docker image with an older jdk version and see what happens.
Ops, actually was @emilburzo that has suspected.
I think @kall is right this seems to be the jdk bug: https://bugs.openjdk.java.net/browse/JDK-8189789 According to the bug description the problem lies in the gzip class. To work around this in tomcat with compression turned on we added the following header to our requests to the server:
Accept-encoding deflate
This ensures that the server uses the deflate mode for compressing the files.
Given https://github.com/docker-library/tomcat/issues/82#issuecomment-338766857 (that this is reproducible with Tomcat outside of a container, and looks to potentially be a JDK bug), I'm going to close since there's not really something we can fix in the image itself to correct this (short of waiting for an updated/fixed JDK).
This thread should serve as a good reference for folks running into this problem in the future. :+1: