Skip to content

Instantly share code, notes, and snippets.

Forked from tmaiaroto/Dockerfile
Created March 27, 2018 14:07
What would you like to do?
WordPress on Amazon ECS
if env | grep -q ^WP_WEBROOT=; then
echo "Replacing nginx webroot for WordPress with environment variable: $WP_WEBROOT"
sed -i 's#root /var/www/html;#root '$WP_WEBROOT';#' /etc/nginx/nginx.conf
echo "INFO: Running /usr/bin/supervisord"
echo "\n\n"
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
FROM alpine:3.3
MAINTAINER Tom Maiaroto <>
# Install packages
RUN apk --update --repository add \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
php7 \
php7-xml \
php7-xmlreader \
php7-xsl \
php7-pdo_mysql \
php7-mcrypt \
php7-curl \
php7-json \
php7-fpm \
php7-phar \
php7-openssl \
php7-mysqli \
php7-ctype \
php7-opcache \
php7-mbstring \
php7-zlib \
php7-gd \
nginx \
supervisor --repository
# Small fixes and cleanup
RUN ln -s /etc/php7 /etc/php && \
ln -s /usr/bin/php7 /usr/bin/php && \
ln -s /usr/sbin/php-fpm7 /usr/bin/php-fpm && \
ln -s /usr/lib/php7 /usr/lib/php && \
rm -fr /var/cache/apk/*
# PHP Composer
RUN curl -sS | php -- --install-dir=/usr/bin --filename=composer
# Configure nginx
COPY config/nginx.conf /etc/nginx/nginx.conf
# Configure PHP-FPM
COPY config/fpm-pool.conf /etc/php7/php-fpm.d/zzz_custom.conf
COPY config/php.ini /etc/php7/conf.d/zzz_custom.ini
# Configure supervisord
COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# This runs supervisord as well as configures some things like nginx's webroot.
COPY config/ /usr/local/bin/
RUN chmod +x /usr/local/bin/
# Note: The NGINX_WEBROOT environment variable should be set to change
# the webroot so that this file is never served.
COPY config/index.php /var/www/html/
# Permissions
RUN chown nginx:www-data -R /var/lib/nginx
RUN chmod -R g+w /var/lib/nginx
# /run/nginx/ needs /run/nginx to exist
RUN mkdir -p /run/nginx
# The following should be set or overwritten when the Docker container runs (ECS Task definition).
# These are used by WordPress.
ENV WP_ENV='development'
ENV WP_HOME='http://localhost'
ENV WP_SITEURL='http://localhost/wp'
# Not used by WordPress, but used by the script to replace
# the webroot in nginx.conf. It should point to where you have WordPress.
ENV WP_WEBROOT='/var/www/html'
EXPOSE 80 1443
CMD ["/usr/local/bin/"]
#! /bin/bash
# Join the default ECS cluster
echo ECS_CLUSTER=default >> /etc/ecs/ecs.config
# Instance should be added to an security group that allows HTTP outbound
yum update
# Install jq, a JSON parser
yum -y install jq
# Install NFS client
if ! rpm -qa | grep -qw nfs-utils; then
yum -y install nfs-utils
if ! rpm -qa | grep -qw python27; then
yum -y install python27
# Install pip
yum -y install python27-pip
# Install awscli
pip install awscli
# Upgrade to the latest version of the awscli
# pip install --upgrade awscli
# Add support for EFS to the CLI configuration
aws configure set preview.efs true
# Create mount point
mkdir /mnt/efs
# Instance needs to be a member of security group that allows 2049
# The security group that the instance belongs to has to be added to EFS file system configuration
# Mount EFS file system
sudo mount -t nfs4 -o nfsvers=4.1 $(curl -s /mnt/efs
# Restart docker (has to be done afer mounting EFS apparently:
sudo service docker restart && sudo start ecs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment