├── Dockerfile ├── README.md ├── config.json ├── default └── run.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:jessie 2 | 3 | # Prepare Debian environment 4 | ENV DEBIAN_FRONTEND noninteractive 5 | 6 | # Performance optimization - see https://gist.github.com/jpetazzo/6127116 7 | # this forces dpkg not to call sync() after package extraction and speeds up install 8 | RUN echo "force-unsafe-io" > /etc/dpkg/dpkg.cfg.d/02apt-speedup 9 | # we don't need an apt cache in a container 10 | RUN echo "Acquire::http {No-Cache=True;};" > /etc/apt/apt.conf.d/no-cache 11 | 12 | # Update and install system base packages 13 | ENV IMAGE_PRODUCTION_APT_GET_DATE 2015-01-07-22-44 14 | RUN apt-get update && \ 15 | apt-get install -y \ 16 | git \ 17 | mercurial \ 18 | curl \ 19 | nginx \ 20 | mysql-client \ 21 | php5-fpm \ 22 | php5-curl \ 23 | php5-cli \ 24 | php5-gd \ 25 | php5-intl \ 26 | php5-mcrypt \ 27 | php5-mysql \ 28 | php5-pgsql \ 29 | php5-xsl && \ 30 | apt-get clean && \ 31 | rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 32 | 33 | # Initialize application 34 | WORKDIR /app 35 | 36 | # Install composer && global asset plugin (Yii 2.0 requirement) 37 | ENV COMPOSER_HOME /root/.composer 38 | ENV PATH /root/.composer/vendor/bin:$PATH 39 | ADD config.json /root/.composer/config.json 40 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \ 41 | /usr/local/bin/composer global require "fxp/composer-asset-plugin" 42 | 43 | # Install application template and packages 44 | # Yii 2.0 application and its extensions can be used directly from the image or serve as local cache 45 | RUN /usr/local/bin/composer create-project --prefer-dist \ 46 | yiisoft/yii2-app-basic:2.* \ 47 | /app 48 | 49 | # Configure nginx 50 | ADD default /etc/nginx/sites-available/default 51 | RUN echo "daemon off;" >> /etc/nginx/nginx.conf && \ 52 | echo "cgi.fix_pathinfo = 0;" >> /etc/php5/fpm/php.ini && \ 53 | sed -i.bak 's/variables_order = "GPCS"/variables_order = "EGPCS"/' /etc/php5/fpm/php.ini && \ 54 | sed -i.bak '/;catch_workers_output = yes/ccatch_workers_output = yes' /etc/php5/fpm/pool.d/www.conf && \ 55 | sed -i.bak 's/log_errors_max_len = 1024/log_errors_max_len = 65536/' /etc/php5/fpm/php.ini 56 | # forward request and error logs to docker log collector 57 | RUN ln -sf /dev/stderr /var/log/nginx/error.log 58 | # /!\ DEVELOPMENT ONLY SETTINGS /!\ 59 | # Running PHP-FPM as root, required for volumes mounted from host 60 | RUN sed -i.bak 's/user = www-data/user = root/' /etc/php5/fpm/pool.d/www.conf && \ 61 | sed -i.bak 's/group = www-data/group = root/' /etc/php5/fpm/pool.d/www.conf && \ 62 | sed -i.bak 's/--fpm-config /-R --fpm-config /' /etc/init.d/php5-fpm 63 | # /!\ DEVELOPMENT ONLY SETTINGS /!\ 64 | 65 | ADD run.sh /root/run.sh 66 | RUN chmod 700 /root/run.sh 67 | 68 | CMD ["/root/run.sh"] 69 | EXPOSE 80 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker Container for Yii 2.0 2 | 3 | --- 4 | 5 | :bangbang: **We've released [`docker-yii2-app`](https://github.com/dmstr/docker-yii2-app) an updated version of a minimalistic Yii 2.0 application template.** 6 | 7 | --- 8 | 9 | 10 | **Basic App Template** 11 | 12 | > Note! This docker container was created as a very basic Yii2 example. 13 | > 14 | > **If you would like to use a Yii 2.0 Framework application with a Docker-optimized setup based on environment variables, you 15 | should have a look at [phd5](https://github.com/dmstr/phd5-app).** 16 | 17 | ## Usage 18 | 19 | Get it from [Docker Hub](https://registry.hub.docker.com/u/schmunk42/yii2-app-basic/)! 20 | 21 | docker pull schmunk42/yii2-app-basic 22 | 23 | Run the container 24 | 25 | docker run -p 8888:80 schmunk42/yii2-app-basic 26 | 27 | Open [http://127.0.0.1:8888](http://127.0.0.1:8888) (Linnx) or [http://192.168.59.103:8888](http://192.168.59.103:8888) (OS X, Windows) in your browser. 28 | 29 | Use `Ctrl+c` to stop the process, you can also start the docker process in the background, by adding the `-d` or `--detach` option. 30 | 31 | ## Development 32 | 33 | Copy the applictaion template from the image to your host, the following command will create a `myapp` app folder in your working directory. 34 | 35 | docker run \ 36 | -v `pwd`/myapp:/app-install \ 37 | schmunk42/yii2-app-basic \ 38 | cp -a /app/. /app-install 39 | 40 | Now as you have the source-code on your host system, mount the application as volume an re-run the container 41 | 42 | cd myapp 43 | 44 | docker run -d -p 8888:80 \ 45 | -v `pwd`:/app \ 46 | --name myapp \ 47 | schmunk42/yii2-app-basic 48 | 49 | Access the application under the URLs mentioned above, you can directly edit the files of your application or run commands like 50 | 51 | docker exec myapp ./yii 52 | 53 | directly off the running container. 54 | 55 | Links 56 | ----- 57 | 58 | - [yii2-app-basic](https://github.com/yiisoft/yii2-app-basic) 59 | - [Phundament 4](http://phundament.com) 60 | - [diemeisterei GmbH](http://diemeisterei.de) 61 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "preferred-install": "dist", 4 | "github-protocols": ["https","http"], 5 | "github-oauth": { 6 | "github.com": "aa9a906cf406370b509bbce3a78829202b41b8e6" 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /default: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80 default_server; 3 | listen [::]:80 default_server ipv6only=on; 4 | 5 | root /app/web; 6 | index index.php; 7 | server_name web; 8 | 9 | location / { 10 | try_files $uri $uri/ /index.php?$args; 11 | } 12 | 13 | location ~ \.php$ { 14 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 15 | # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini 16 | 17 | fastcgi_pass unix:/var/run/php5-fpm.sock; 18 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 19 | fastcgi_index index.php; 20 | include fastcgi_params; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | function setEnvironmentVariable() { 6 | if [ -z "$2" ]; then 7 | echo "Environment variable '$1' not set." 8 | return 9 | fi 10 | echo "env[$1] = \"$2\"" >> /etc/php5/fpm/pool.d/www.conf 11 | } 12 | 13 | # Grep all ENV variables 14 | for _curVar in `env | awk -F = '{print $1}'`;do 15 | # awk has split them by the equals sign 16 | # Pass the name and value to our function 17 | setEnvironmentVariable ${_curVar} ${!_curVar} 18 | done 19 | 20 | # prepare log output 21 | mkdir -p /app/runtime/logs /app/web/assets 22 | touch /var/log/nginx/access.log \ 23 | /var/log/nginx/error.log \ 24 | /app/runtime/logs/web.log \ 25 | /app/runtime/logs/console.log 26 | # adjust folder permissions for docker volume usage 27 | find /app/runtime -type d -print0 | xargs -0 chmod 777 28 | find /app/runtime -type f -print0 | xargs -0 chmod 666 29 | find /app/web/assets -type d -print0 | xargs -0 chmod 777 30 | find /app/web/assets -type f -print0 | xargs -0 chmod 666 31 | 32 | # start PHP and nginx 33 | service php5-fpm start 34 | /usr/sbin/nginx 35 | --------------------------------------------------------------------------------