New Dockerfile based on Alpine Linux and Nginx/PHP-FPM

This commit is contained in:
Frederic Guillot 2016-02-06 20:00:26 -05:00
parent 58cef28967
commit 77a91b7ade
12 changed files with 183 additions and 26 deletions

1
.docker/crontab/kanboard Normal file
View File

@ -0,0 +1 @@
1 0 * * * cd /var/www/kanboard && ./kanboard cronjob >/dev/null 2>&1

70
.docker/nginx/nginx.conf Normal file
View File

@ -0,0 +1,70 @@
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
server_tokens off;
access_log off;
error_log /dev/stderr;
server {
listen 80;
server_name localhost;
index index.php;
root /var/www/kanboard;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
location /data {
return 404;
}
location ~* ^.+\.(log|sqlite)$ {
return 404;
}
location ~ /\.ht {
return 404;
}
location ~* ^.+\.(ico|jpg|gif|png|css|js|svg|eot|ttf|woff|woff2|otf)$ {
expires 7d;
etag on;
}
gzip on;
gzip_comp_level 3;
gzip_disable "msie6";
gzip_vary on;
gzip_types
text/javascript
application/javascript
application/json
text/xml
application/xml
application/rss+xml
text/css
text/plain;
}
}

View File

@ -0,0 +1,15 @@
expose_php = Off
error_reporting = E_ALL
display_errors = Off
log_errors = On
error_log = syslog
date.timezone = UTC
allow_url_fopen = On
post_max_size = 30M
upload_max_filesize = 30M
opcache.max_accelerated_files = 7963
opcache.validate_timestamps = Off
opcache.save_comments = 0
opcache.load_comments = 0
opcache.fast_shutdown = 1
opcache.enable_file_override = On

17
.docker/php/php-fpm.conf Normal file
View File

@ -0,0 +1,17 @@
[global]
error_log = /dev/stderr
log_level = error
daemonize = no
[www]
user = nginx
group = nginx
listen.owner = nginx
listen.group = nginx
listen = /var/run/php-fpm.sock
pm = dynamic
pm.max_children = 20
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 2048

View File

@ -0,0 +1,2 @@
#!/bin/sh
/bin/true

2
.docker/services.d/cron/run Executable file
View File

@ -0,0 +1,2 @@
#!/bin/execlineb -P
crond -f

2
.docker/services.d/nginx/run Executable file
View File

@ -0,0 +1,2 @@
#!/bin/execlineb -P
nginx -g "daemon off;"

2
.docker/services.d/php/run Executable file
View File

@ -0,0 +1,2 @@
#!/bin/execlineb -P
php-fpm -F

View File

@ -23,6 +23,7 @@ New features:
Improvements: Improvements:
* New Dockerfile based on Alpine Linux and Nginx/PHP-FPM
* The date time format can be chosen in application settings * The date time format can be chosen in application settings
* Export only open tasks in iCal feed * Export only open tasks in iCal feed
* Remove time form on task summary page and move that to task edit form * Remove time form on task summary page and move that to task edit form

View File

@ -1,23 +1,33 @@
FROM ubuntu:14.04 FROM gliderlabs/alpine:latest
MAINTAINER Frederic Guillot <fred@kanboard.net> MAINTAINER Frederic Guillot <fred@kanboard.net>
RUN apt-get update && apt-get install -y apache2 php5 php5-gd php5-ldap php5-sqlite git curl && apt-get clean RUN apk-install nginx bash ca-certificates s6 curl \
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf && a2enmod rewrite php-fpm php-json php-zlib php-xml php-dom php-ctype php-opcache php-zip \
RUN sed -ri 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf php-pdo php-pdo_mysql php-pdo_sqlite php-pdo_pgsql php-ldap \
RUN curl -sS https://getcomposer.org/installer | php -- --filename=/usr/local/bin/composer php-gd php-mcrypt php-openssl php-phar \
RUN cd /var/www && git clone --depth 1 https://github.com/fguillot/kanboard.git && curl -sS https://getcomposer.org/installer | php -- --filename=/usr/local/bin/composer
RUN cd /var/www/kanboard && composer --prefer-dist --no-dev --optimize-autoloader --quiet install
RUN rm -rf /var/www/html && mv /var/www/kanboard /var/www/html
RUN chown -R www-data:www-data /var/www/html/data
VOLUME /var/www/html/data RUN cd /var/www \
&& wget https://github.com/fguillot/kanboard/archive/master.zip \
&& unzip -qq master.zip \
&& rm -f *.zip \
&& mv kanboard-master kanboard \
&& cd /var/www/kanboard && composer --prefer-dist --no-dev --optimize-autoloader --quiet install \
&& chown -R nginx:nginx /var/www/kanboard \
&& chown -R nginx:nginx /var/lib/nginx
COPY .docker/services.d /etc/services.d
COPY .docker/php/conf.d/local.ini /etc/php/conf.d/
COPY .docker/php/php-fpm.conf /etc/php/
COPY .docker/nginx/nginx.conf /etc/nginx/
COPY .docker/kanboard/config.php /var/www/kanboard/
COPY .docker/kanboard/config.php /var/www/kanboard/
COPY .docker/crontab/kanboard /var/spool/cron/crontabs/nginx
EXPOSE 80 EXPOSE 80
ENV APACHE_RUN_USER www-data VOLUME /var/www/kanboard/data
ENV APACHE_RUN_GROUP www-data VOLUME /var/www/kanboard/plugins
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
CMD /usr/sbin/apache2ctl -D FOREGROUND ENTRYPOINT ["/bin/s6-svscan", "/etc/services.d"]
CMD []

View File

@ -62,6 +62,7 @@ archive:
@ rm -rf ${BUILD_DIR}/kanboard/*.markdown @ rm -rf ${BUILD_DIR}/kanboard/*.markdown
@ rm -rf ${BUILD_DIR}/kanboard/*.lock @ rm -rf ${BUILD_DIR}/kanboard/*.lock
@ rm -rf ${BUILD_DIR}/kanboard/*.json @ rm -rf ${BUILD_DIR}/kanboard/*.json
@ rm -rf ${BUILD_DIR}/kanboard/.docker
@ cd ${BUILD_DIR}/kanboard && find ./vendor -name doc -type d -exec rm -rf {} +; @ cd ${BUILD_DIR}/kanboard && find ./vendor -name doc -type d -exec rm -rf {} +;
@ cd ${BUILD_DIR}/kanboard && find ./vendor -name notes -type d -exec rm -rf {} +; @ cd ${BUILD_DIR}/kanboard && find ./vendor -name notes -type d -exec rm -rf {} +;
@ cd ${BUILD_DIR}/kanboard && find ./vendor -name test -type d -exec rm -rf {} +; @ cd ${BUILD_DIR}/kanboard && find ./vendor -name test -type d -exec rm -rf {} +;
@ -134,4 +135,13 @@ sql:
@ let pg_version=`psql -U postgres -A -c 'copy(select version from schema_version) to stdout;' kanboard` ;\ @ let pg_version=`psql -U postgres -A -c 'copy(select version from schema_version) to stdout;' kanboard` ;\
echo "INSERT INTO schema_version VALUES ('$$pg_version');" >> app/Schema/Sql/postgres.sql echo "INSERT INTO schema_version VALUES ('$$pg_version');" >> app/Schema/Sql/postgres.sql
docker-image:
@ docker build -t kanboard/kanboard:latest .
docker-push:
@ docker push kanboard/kanboard:latest
docker-run:
@ docker run -d --name kanboard -p 80:80 -t kanboard/kanboard:latest
.PHONY: all .PHONY: all

View File

@ -2,7 +2,18 @@ How to run Kanboard with Docker?
================================ ================================
Kanboard can run easily with [Docker](https://www.docker.com). Kanboard can run easily with [Docker](https://www.docker.com).
There is a `Dockerfile` in the repository to build your own container.
The image size is approximately **50MB** and contains:
- [Alpine Linux](http://alpinelinux.org/)
- The [process manager S6](http://skarnet.org/software/s6/)
- Nginx
- PHP-FPM
The Kanboard cronjob is also running everyday at midnight.
URL rewriting is enabled in the included config file.
When the container is running, the memory utilization is around **20MB**.
Use the stable version Use the stable version
---------------------- ----------------------
@ -17,7 +28,7 @@ docker run -d --name kanboard -p 80:80 -t kanboard/kanboard:stable
Use the development version (automated build) Use the development version (automated build)
--------------------------------------------- ---------------------------------------------
Every new commit on the repository trigger a new build on [Docker Hub](https://registry.hub.docker.com/u/kanboard/kanboard/). Every new commit on the repository trigger a new build on the [Docker Hub](https://registry.hub.docker.com/u/kanboard/kanboard/).
```bash ```bash
docker pull kanboard/kanboard docker pull kanboard/kanboard
@ -29,31 +40,45 @@ The tag **latest** is the **development version** of Kanboard, use at your own r
Build your own Docker image Build your own Docker image
--------------------------- ---------------------------
There is a `Dockerfile` in the Kanboard repository to build your own image.
Clone the Kanboard repository and run the following command: Clone the Kanboard repository and run the following command:
```bash ```bash
docker build -t youruser/kanboard:master . docker build -t youruser/kanboard:master .
``` ```
To run your image in background on the port 80: or
```bash
make docker-image
```
To run your container in background on the port 80:
```bash ```bash
docker run -d --name kanboard -p 80:80 -t youruser/kanboard:master docker run -d --name kanboard -p 80:80 -t youruser/kanboard:master
``` ```
Store your data on a volume Volumes
--------------------------- -------
By default Kanboard will store attachments and the Sqlite database in the directory data. Run this command to use a custom volume path: You can attach 2 volumes to your container:
```bash - Data folder: `/var/www/kanboard/data`
docker run -d --name kanboard -v /your/local/data/folder:/var/www/html/data -p 80:80 -t kanboard/kanboard:master - Plugins folder: `/var/www/kanboard/plugins`
```
Use the flag `-v` to mount a volume on the host machine like described in [official Docker documentation](https://docs.docker.com/engine/userguide/containers/dockervolumes/).
Config files
------------
- The container already include a custom config file located at `/var/www/kanboard/config.php`.
- You can store your own config file on the data volume: `/var/www/kanboard/data/config.php`.
References References
---------- ----------
- [Official Kanboard images](https://registry.hub.docker.com/u/kanboard/kanboard/) - [Official Kanboard images](https://registry.hub.docker.com/u/kanboard/kanboard/)
- [Docker documentation](https://docs.docker.com/) - [Docker documentation](https://docs.docker.com/)
- [Dockerfile stable version](https://github.com/kanboard/docker/blob/master/Dockerfile) - [Dockerfile stable version](https://github.com/kanboard/docker)
- [Dockerfile dev version](https://github.com/fguillot/kanboard/blob/master/Dockerfile) - [Dockerfile dev version](https://github.com/fguillot/kanboard/blob/master/Dockerfile)