Skip to content

set container port with env variables #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile-apache
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ARG PHP_VER_DOT
FROM jtreminio/php:$PHP_VER_DOT
LABEL maintainer="Juan Treminio <jtreminio@gmail.com>"


RUN printf "deb [arch=amd64] http://ppa.launchpad.net/ondrej/apache2/ubuntu bionic main\n" \
>/etc/apt/sources.list.d/ondrej-apache2.list &&\
apt-get update &&\
Expand All @@ -13,7 +14,7 @@ RUN printf "deb [arch=amd64] http://ppa.launchpad.net/ondrej/apache2/ubuntu bion
RUN a2enmod env headers proxy proxy_http proxy_fcgi rewrite

# Set proper permissions for Apache
RUN chown -R www-data:www-data \
RUN chown -R www:www \
/var/www &&\
rm -rf /var/www/html

Expand Down
3 changes: 0 additions & 3 deletions Dockerfile-env
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,6 @@ ENV PHP.allow_url_fopen=1 \
PHP.mbstring.detect_order= \
PHP.mbstring.encoding_translation=0 \
PHP.mbstring.func_overload=0 \
PHP.mbstring.http_input= \
PHP.mbstring.http_output= \
PHP.mbstring.internal_encoding= \
PHP.mbstring.language=neutral \
PHP.mbstring.script_encoding= \
PHP.mbstring.strict_detection=0 \
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile-nginx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ARG PHP_VER_DOT
FROM jtreminio/php:$PHP_VER_DOT
LABEL maintainer="Juan Treminio <jtreminio@gmail.com>"


RUN printf "deb [arch=amd64] http://ppa.launchpad.net/ondrej/nginx/ubuntu bionic main\n" \
>/etc/apt/sources.list.d/ondrej-nginx.list &&\
apt-get update &&\
Expand All @@ -12,10 +13,10 @@ RUN printf "deb [arch=amd64] http://ppa.launchpad.net/ondrej/nginx/ubuntu bionic
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/{man,doc}

# Set proper permissions for Nginx
RUN chown -R www-data:www-data \
RUN chown -R www:www \
/var/lib/nginx \
/var/www &&\
install -d -m 0755 -o www-data -g www-data \
install -d -m 0755 -o www -g www \
/var/cache/nginx \
/var/run/nginx &&\
rm -rf /var/www/html
Expand Down
12 changes: 10 additions & 2 deletions Dockerfile-php-cli
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ LABEL maintainer="Juan Treminio <jtreminio@gmail.com>"
ENV DEBIAN_FRONTEND=noninteractive
ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn


# set container user
ARG WWWGID=1000
ARG WWWUID=1000
RUN groupadd --force -g $WWWGID www \
&& useradd -ms /bin/bash --no-user-group -g $WWWGID -u $WWWUID www


RUN update-alternatives --install /bin/sh sh /bin/bash 100

RUN mkdir /docker_build
Expand Down Expand Up @@ -32,12 +40,12 @@ RUN /docker_build/bin_install_composer.sh &&\
COPY files/php/php.ini /etc/php/php.ini

# Default sessions directory
RUN install -d -m 0755 -o www-data -g www-data /var/lib/php/sessions
RUN install -d -m 0755 -o www -g www /var/lib/php/sessions

# Xdebug CLI debugging
COPY files/php/xdebug /usr/bin/xdebug
RUN chmod +x /usr/bin/xdebug

WORKDIR /etc/php/${PHP_VER}

USER www-data
USER www
2 changes: 1 addition & 1 deletion Dockerfile-php-fpm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ COPY files/php/php-fpm /etc/service/fpm/run
RUN chmod +x /etc/service/fpm/run

# PID directory
RUN install -d -m 0755 -o www-data -g www-data /var/run/php-fpm
RUN install -d -m 0755 -o www -g www /var/run/php-fpm

EXPOSE 9000

Expand Down
4 changes: 2 additions & 2 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function main() {

function build_env_image() {
echo "Building ENV"
docker image build \
docker image build \
-t jtreminio/phpenv:latest \
-f Dockerfile-env \
.
Expand Down Expand Up @@ -247,7 +247,7 @@ function build_nginx_image() {
PHP_MINOR="${2}"

echo "Building PHP ${PHP_MAJOR} + Nginx"
docker image build \
docker image build --no-cache \
--build-arg PHP_VER_DOT=${PHP_MINOR} \
-t jtreminio/php-nginx:${PHP_MAJOR} \
-t jtreminio/php-nginx:${PHP_MINOR} \
Expand Down
2 changes: 1 addition & 1 deletion files/apache/ports.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

ServerName localhost

Listen 8080
Listen ${CONTAINER_PORT}
2 changes: 1 addition & 1 deletion files/apache/vhost/drupal.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /etc/apache2/sites-available/drupal.conf
# Drupal

<VirtualHost *:8080>
<VirtualHost *:${CONTAINER_PORT}>
ServerName default.localhost
ServerAlias *

Expand Down
2 changes: 1 addition & 1 deletion files/apache/vhost/fpm.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /etc/apache2/sites-available/fpm.conf
# Basic FPM

<VirtualHost *:8080>
<VirtualHost *:${CONTAINER_PORT}>
ServerName default.localhost
ServerAlias *

Expand Down
2 changes: 1 addition & 1 deletion files/apache/vhost/html.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /etc/apache2/sites-available/html.conf
# Basic HTML

<VirtualHost *:8080>
<VirtualHost *:${CONTAINER_PORT}>
ServerName default.localhost
ServerAlias *

Expand Down
2 changes: 1 addition & 1 deletion files/apache/vhost/laravel.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /etc/apache2/sites-available/laravel.conf
# Laravel

<VirtualHost *:8080>
<VirtualHost *:${CONTAINER_PORT}>
ServerName default.localhost
ServerAlias *

Expand Down
2 changes: 1 addition & 1 deletion files/apache/vhost/symfony2.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /etc/apache2/sites-available/symfony2.conf
# Symfony 2

<VirtualHost *:8080>
<VirtualHost *:${CONTAINER_PORT}>
ServerName default.localhost
ServerAlias *

Expand Down
2 changes: 1 addition & 1 deletion files/apache/vhost/symfony3.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /etc/apache2/sites-available/symfony3.conf
# Symfony 3

<VirtualHost *:8080>
<VirtualHost *:${CONTAINER_PORT}>
ServerName default.localhost
ServerAlias *

Expand Down
2 changes: 1 addition & 1 deletion files/apache/vhost/symfony4.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /etc/apache2/sites-available/symfony4.conf
# Symfony 4

<VirtualHost *:8080>
<VirtualHost *:${CONTAINER_PORT}>
ServerName default.localhost
ServerAlias *

Expand Down
2 changes: 1 addition & 1 deletion files/apache/vhost/wordpress.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /etc/apache2/sites-available/wordpress.conf
# Wordpress

<VirtualHost *:8080>
<VirtualHost *:${CONTAINER_PORT}>
ServerName default.localhost
ServerAlias *

Expand Down
2 changes: 1 addition & 1 deletion files/nginx/nginx
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ if [[ ! -f /etc/nginx/sites-enabled/default ]]; then
ln -s /etc/nginx/sites-available/${VHOST} /etc/nginx/sites-enabled/default
fi

exec nginx -g "daemon off; env PHPFPM_XDEBUG_PORT=${PHPFPM_XDEBUG_PORT};"
exec nginx -g "daemon off; env PHPFPM_XDEBUG_PORT=${PHPFPM_XDEBUG_PORT};" # env CONTAINER_PORT=${CONTAINER_PORT};" tried to add this, but it doesn't work
11 changes: 7 additions & 4 deletions files/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# /etc/nginx/nginx.conf

user www-data;
user www;

worker_processes auto;
pid /var/run/nginx/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;



error_log /dev/stderr warn;

events {
Expand All @@ -30,7 +32,7 @@ http {
gzip on;
gzip_disable "msie6";

client_max_body_size 10m;
client_max_body_size 50m;
client_body_buffer_size 128k;

proxy_redirect off;
Expand All @@ -47,6 +49,7 @@ http {

# Default to NOT using Xdebug, falling back to standard :9000 for PHP-FPM
perl_set $phpfpm_xdebug_port 'sub { return $ENV{"PHPFPM_XDEBUG_PORT"}; }';

perl_set $nginxport 'sub { return $ENV{"CONTAINER_PORT"}; }';

include /etc/nginx/sites-enabled/default;
}
}
2 changes: 1 addition & 1 deletion files/nginx/vhost/drupal6.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ map $cookie_XDEBUG_SESSION $my_fastcgi_pass {
}

server {
listen *:8080 default_server;
listen *:${nginxport} default_server;

server_name _;
root /var/www;
Expand Down
2 changes: 1 addition & 1 deletion files/nginx/vhost/drupal7.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ map $cookie_XDEBUG_SESSION $my_fastcgi_pass {
}

server {
listen *:8080 default_server;
listen *:${nginxport} default_server;

server_name _;
root /var/www;
Expand Down
2 changes: 1 addition & 1 deletion files/nginx/vhost/drupal8.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ map $cookie_XDEBUG_SESSION $my_fastcgi_pass {
}

server {
listen *:8080 default_server;
listen *:${nginxport} default_server;

server_name _;
root /var/www;
Expand Down
2 changes: 1 addition & 1 deletion files/nginx/vhost/fpm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ map $cookie_XDEBUG_SESSION $my_fastcgi_pass {
}

server {
listen *:8080 default_server;
listen *:${nginxport} default_server;

server_name _;
root /var/www;
Expand Down
2 changes: 1 addition & 1 deletion files/nginx/vhost/html.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Basic HTML

server {
listen *:8080 default_server;
listen *:${nginxport} default_server;

server_name _;
root /var/www;
Expand Down
5 changes: 4 additions & 1 deletion files/nginx/vhost/laravel.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ map $cookie_XDEBUG_SESSION $my_fastcgi_pass {
}

server {
listen *:8080 default_server;
listen *:${nginxport} default_server;

server_name _;
root /var/www/public;
Expand Down Expand Up @@ -42,4 +42,7 @@ server {
location ~ /\.(?!well-known).* {
deny all;
}

error_log /var/log/nginx/error.log error;
access_log /var/log/nginx/access.log;
}
2 changes: 1 addition & 1 deletion files/nginx/vhost/symfony2-dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ map $cookie_XDEBUG_SESSION $my_fastcgi_pass {
}

server {
listen *:8080 default_server;
listen *:${nginxport} default_server;

server_name _;
root /var/www/web;
Expand Down
2 changes: 1 addition & 1 deletion files/nginx/vhost/symfony2-prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ map $cookie_XDEBUG_SESSION $my_fastcgi_pass {
}

server {
listen *:8080 default_server;
listen *:${nginxport} default_server;

server_name _;
root /var/www/web;
Expand Down
2 changes: 1 addition & 1 deletion files/nginx/vhost/symfony3-dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ map $cookie_XDEBUG_SESSION $my_fastcgi_pass {
}

server {
listen *:8080 default_server;
listen *:${nginxport} default_server;

server_name _;
root /var/www/web;
Expand Down
2 changes: 1 addition & 1 deletion files/nginx/vhost/symfony3-prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ map $cookie_XDEBUG_SESSION $my_fastcgi_pass {
}

server {
listen *:8080 default_server;
listen *:${nginxport} default_server;

server_name _;
root /var/www/web;
Expand Down
2 changes: 1 addition & 1 deletion files/nginx/vhost/symfony4.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ map $cookie_XDEBUG_SESSION $my_fastcgi_pass {
}

server {
listen *:8080 default_server;
listen *:${nginxport} default_server;

server_name _;
root /var/www/public;
Expand Down
37 changes: 32 additions & 5 deletions files/nginx/vhost/wordpress.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,35 @@ map $cookie_XDEBUG_SESSION $my_fastcgi_pass {
}

server {
listen *:8080 default_server;
listen *:${nginxport} default_server;

server_name _;
root /var/www;
index index.php;


location / {
try_files $uri /index.php$is_args$args;
#try_files $uri /index.php$is_args$args;
try_files $uri $uri/ /index.php?$args;
}

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

# WPLM fix
rewrite ^/en/wp-login.php /wp-login.php break;
rewrite ^/de/wp-login.php /wp-login.php break;
rewrite ^/fr/wp-login.php /wp-login.php break;
rewrite ^/es/wp-login.php /wp-login.php break;
rewrite ^/it/wp-login.php /wp-login.php break;

location ~ ^/index\.php(/|$) {
location ~ \.php(/|$) {
set $path_info $fastcgi_path_info;

fastcgi_pass $my_fastcgi_pass;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.*)$;

include fastcgi_params;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
Expand All @@ -49,8 +59,25 @@ server {
location ~ /\. {
deny all;
}

location ~ /\.svn/* {
deny all;
}

location ~* /(?:uploads|files)/.*\.php$ {
location ~ /\.git/* {
deny all;
}

location /nginx_status {
stub_status on;
access_log off;
}

location ~ ^/(status|ping)$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
allow 127.0.0.1;
deny all;
}
}
Loading