Skip to content

Instantly share code, notes, and snippets.

@anandpathak
Last active August 8, 2016 16:53
Show Gist options
  • Save anandpathak/ceac95f2d438ae89a657a0e3b0be2ec7 to your computer and use it in GitHub Desktop.
Save anandpathak/ceac95f2d438ae89a657a0e3b0be2ec7 to your computer and use it in GitHub Desktop.
Dockerfile :- image contians apache2, php-fpm, mysql-client,git and ssh
Folder Structure
* |->Docker-composer
|-> configuration
|-> apache2
|-> vhost
|->site-available
|--> default.conf
|->site-enabled
|-->default.conf
|->mysql
|-->custom.cnf
|-->localdb-run.sh
|->database //contains database file
|->logs //contains logs
|-->docker-composer.yaml
|->docker-image
|-->Dockerfile
|-->php-fpm.conf
|-->supervisord.conf
|->docroot //contains code
version: '2'
services:
web:
build: `Link-to-Dockerfile`
image: anandpathak/lamp
ports:
- "9090:80"
- "2222:22"
- "4443:43"
volumes:
- ../docroot:/var/www/html/
- ./configuration/apache2/vhost/sites-available:/etc/apache2/sites-available/
- ./configuration/apache2/vhost/sites-enabled:/etc/apache2/sites-enabled/
- ./logs/apache2:/var/log/apache2/
environment:
- ""
links:
- db
db:
image: mysql:5.6
entrypoint:
- /localdb-run.sh
environment:
- MYSQL_ROOT_PASSWORD=admin
volumes:
- ./database:/var/lib/mysql/
- ./configuration/mysql/custom.cnf:/etc/mysql/conf.d/custom.cnf
- ./logs/mysql:/var/log/mysql/
- ./configuration/mysql/localdb-run.sh:/localdb-run.sh
FROM ubuntu:14.04
MAINTAINER Anand Pathak <anandpathak69@gmail.com>
RUN echo "deb http://mirrors.digitalocean.com/ubuntu trusty main multiverse" >> /etc/apt/sources.list && \
echo "deb http://mirrors.digitalocean.com/ubuntu trusty-updates main multiverse" >> /etc/apt/sources.list && \
echo "deb http://security.ubuntu.com/ubuntu trusty-security main multiverse" >> /etc/apt/sources.list
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:root' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
RUN apt-get install -y apache2-mpm-worker libapache2-mod-fastcgi php5-fpm php5-mysql mysql-client php5-gd php5-curl curl php5-cli php5-memcached supervisor && \
echo "ServerName localhost" | tee /etc/apache2/conf-available/servername.conf && \
a2enconf servername && \
a2enmod actions fastcgi rewrite alias
ADD php5-fpm.conf /etc/apache2/conf-available/php5-fpm.conf
RUN a2enconf php5-fpm.conf && \
sed -i 's/;listen = \/var\/run\/php5-fpm.sock/listen = \/var\/run\/php5-fpm.sock/' /etc/php5/fpm/pool.d/www.conf && sed -i 's/\;listen.mode/listen.mode/' /etc/php5/fpm/pool.d/www.conf && sed -i 's/expose_php.*/expose_php = off/g' /etc/php5/fpm/php.ini && sed -i 's/allow_url_fopen.*/allow_url_fopen = off/g' /etc/php5/fpm/php.ini
RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN apt-get install -y git && \
curl -sS https://getcomposer.org/installer | php && \
mv composer.phar /usr/local/bin/composer && \
composer global require drush/drush:8.* && \
composer global update && \
ln -s /root/.composer/vendor/bin/drush /usr/local/bin/drush && \
curl https://drupalconsole.com/installer -L -o drupal.phar && \
mv drupal.phar /usr/local/bin/drupal && \
chmod +x /usr/local/bin/drupal
EXPOSE 80 443 22
CMD ["/usr/bin/supervisord"]
#!/bin/bash
#Make it executable with `chmod a+x /configuration/mysql/localdb-run.sh`
set -e # fail on any error
echo '* Working around permission errors locally by making sure that "mysql" uses the same uid and gid as the host volume'
TARGET_UID=$(stat -c "%u" /var/lib/mysql)
echo '-- Setting mysql user to use uid '$TARGET_UID
usermod -o -u $TARGET_UID mysql || true
TARGET_GID=$(stat -c "%g" /var/lib/mysql)
echo '-- Setting mysql group to use gid '$TARGET_GID
groupmod -o -g $TARGET_GID mysql || true
echo
echo '* Starting MySQL'
chown -R mysql:root /var/run/mysqld/
/entrypoint.sh mysqld --user=mysql --console
<IfModule mod_fastcgi.c>
Alias /php-fcgi /usr/lib/cgi-bin/php5
AddHandler php .php
Action php /php-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5 -socket /var/run/php5-fpm.sock -idle-timeout 300
<Directory /usr/lib/cgi-bin>
AllowOverride All
Options +ExecCGI +FollowSymLinks
Require all granted
</Directory>
</IfModule>
[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D
[program:apache2]
command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"
[program:php-fpm]
command=/etc/init.d/php5-fpm restart -D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment