Nginx (pronounced “engine-x”) is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer, HTTP cache, and a web server (origin server). The nginx project started with a strong focus on high concurrency, high performance and low memory usage.
The nginx-pagespeed brings all the goods of nginx and pagespeed together in one single small alpine docker image. Nginx-pagespeed aims to be 100% compatible with the plain nginx images. Meaning, nginx-pagespeed can be a safe drop-in replacement for any container running
Nginx-pagespeed makes it easy to start optimizing your website by reducing page load time, without requiring you to modify existing content.
$ docker run --name pagespeed-nginx -v /some/content:/usr/share/nginx/html:ro -d pagespeed/nginx-pagespeed
Alternatively, a simple
Dockerfile can be used to generate a new image that includes the necessary content (which is a much cleaner solution than the bind mount above):
FROM pagespeed/nginx-pagespeed COPY static-html-directory /usr/share/nginx/html
Place this file in the same directory as your directory of content (“static-html-directory”), run
docker build -t some-content-ngxpagespeed ., then start your container:
$ docker run --name my-nginx-pagespeed -d some-content-ngxpagespeed
$ docker run --name my-nginx-pagespeed -d -p 8080:80 some-content-ngxpagespeed
Then you can hit
http://host-ip:8080 in your browser.
$ docker run --name my-custom-nginx-pagespeed -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d pagespeed/nginx-pagespeed
For information on the syntax of the nginx configuration files, see the official documentation (specifically the Beginner's Guide). For pagespeed specific nginx config syntax, see Beginner's guide or a complete overview of all pagespeed filters. For a quick start on pagespeed specific configuration see 
If you wish to adapt the default configuration, use something like the following to copy it from a running nginx-pagespeed container:
$ docker run --name tmp-ngxpagespeed-container -d pagespeed/nginx-pagespeed $ docker cp tmp-ngxpagespeed-container:/etc/nginx/nginx.conf /host/path/nginx.conf $ docker rm -f tmp-ngxpagespeed-container
This can also be accomplished more cleanly using a simple
FROM pagespeed/nginx-pagespeed COPY nginx.conf /etc/nginx/nginx.conf
If you add a custom
CMD in the Dockerfile, be sure to include
-g daemon off; in the
CMD in order for nginx to stay in the foreground, so that Docker can track the process properly (otherwise your container will stop immediately after starting)!
Then build the image with
docker build -t custom-ngxpagespeed . and run it as follows:
$ docker run --name my-custom-ngxpagespeed-container -d custom-ngxpagespeed
Out-of-the-box, nginx doesn't support environment variables inside most configuration blocks. But
envsubst may be used as a workaround if you need to generate your nginx configuration dynamically before nginx starts.
Here is an example using docker-compose.yml:
web: image: pagespeed/nginx-pagespeed volumes: - ./mysite.template:/etc/nginx/conf.d/mysite.template ports: - "8080:80" environment: - NGINX_HOST=foobar.com - NGINX_PORT=80 command: /bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
mysite.template file may then contain variable references like this:
pagespeed/nginx-pagespeed images come in many flavors, each designed for a specific use case.
This is the defacto image. If you are unsure about what your needs are, you probably want to use this one. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as the base to build other images off of.
This image has the most up-to-date system packages available in the Alpine Linux project. This means the latest LibreSSL and musl-libc, with the downside of having less tested system packages.
docker build -t <image_tag> <dockerfile_path> . $ docker build -t ngxpagespeed-alpine38-ngxstable stable/3.8/nginx-stable Refer this for additional options.
$ docker run -d -p 80:80 <image_tag>
Refer this for additional options.
3 GB of free diskspace
Apache PageSpeed is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
View PageSpeed license information View Nginx license information
As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).
Some additional license information which was able to be auto-detected might be found in the
As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.