diff --git a/Dockerfile b/Dockerfile index 520c6f1d..45f14daf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,8 +14,25 @@ # otherwise the container won't start) # sudo docker.io run -d -p 22 -p 25:25 -p 53:53/udp -p 443:443 -p 587:587 -p 993:993 box -FROM ubuntu:14.04 +########################################### + +# We need a better starting image than docker's ubuntu image because that +# base image doesn't provide enough to run most Ubuntu services. See +# http://phusion.github.io/baseimage-docker/ for an explanation. They +# provide a better image, but their latest is for an earlier Ubuntu +# version. When they get to Ubuntu 14.04 we'll want to use: +# +# FROM phusion/baseimage: +# +# Until then, use an upgraded image provided by @pjz, based on his +# PR: https://github.com/phusion/baseimage-docker/pull/64 + +FROM pjzz/phusion-baseimage:0.9.10 + # based originally on ubuntu:14.04 + +# Dockerfile metadata. MAINTAINER Joshua Tauberer (http://razor.occams.info) +EXPOSE 22 25 53 443 587 993 # We can't know these values ahead of time, so set them to something # obviously local. The start.sh script will need to be run again once @@ -28,8 +45,8 @@ ENV PUBLIC_IP 192.168.200.1 ENV DISABLE_FIREWALL 1 # Our install will fail if SSH is installed and allows password-based authentication. -RUN DEBIAN_FRONTEND=noninteractive apt-get install -qq -y openssh-server -RUN sed -i /etc/ssh/sshd_config -e "s/^#PasswordAuthentication yes/PasswordAuthentication no/g" +# The base image already installs openssh-server. Just edit its configuration. +RUN sed -i -e "s/^#*\s*PasswordAuthentication \(yes\|no\)/PasswordAuthentication no/g" /etc/ssh/sshd_config # Add this repo into the image so we have the configuration scripts. ADD scripts /usr/local/mailinabox/scripts @@ -37,9 +54,11 @@ ADD conf /usr/local/mailinabox/conf ADD tools /usr/local/mailinabox/tools # Start the configuration. -RUN cd /usr/local/mailinabox; scripts/start.sh +RUN cd /usr/local/mailinabox && scripts/start.sh -# How the instance is launched. +# Configure services for docker. ADD containers/docker /usr/local/mailinabox/containers/docker -CMD bash /usr/local/mailinabox/containers/docker/start_services.sh -EXPOSE 22 25 53 443 587 993 +RUN /usr/local/mailinabox/containers/docker/setup_services.sh + +# How the container is launched. +CMD bash /usr/local/mailinabox/containers/docker/container_start.sh diff --git a/containers/docker/start_services.sh b/containers/docker/container_start.sh old mode 100644 new mode 100755 similarity index 75% rename from containers/docker/start_services.sh rename to containers/docker/container_start.sh index 08bafe46..cb13d0ff --- a/containers/docker/start_services.sh +++ b/containers/docker/container_start.sh @@ -20,15 +20,6 @@ if grep "^PUBLIC_IP=192.168.200.1" /etc/mailinabox.conf > /dev/null; then scripts/start.sh fi -echo "Starting Mail-in-a-Box services..." - -service nsd start -service postfix start -dovecot # it's integration with Upstart doesn't work in docker -service opendkim start -service nginx start -service php-fastcgi start - if [ -t 0 ] then # This is an interactive shell. You get a command prompt within @@ -40,11 +31,11 @@ then bash else - # This is a non-interactive shell. It loops forever to prevent - # the docker container from stopping. + # This is a non-interactive shell. Just display status. Because + # other services are running, the container remains running after + # this script exits. # # You get here by omitting '-t' from the docker run arguments. echo "Your Mail-in-a-Box is running..." - while true; do sleep 10; done fi diff --git a/containers/docker/setup_services.sh b/containers/docker/setup_services.sh new file mode 100755 index 00000000..eb8a6ec5 --- /dev/null +++ b/containers/docker/setup_services.sh @@ -0,0 +1,58 @@ +#!/bin/bash +echo "Setting up Mail-in-a-Box services..." + +SERVICES="nsd postfix dovecot opendkim nginx php-fastcgi" + +for service in $SERVICES; do + mkdir -p /etc/service/$service +done + +cat </etc/service/nsd/run +#!/bin/sh +exec /usr/bin/nsd -d +EORUN + +cat </etc/service/postfix/run +#!/bin/sh +# from http://smarden.org/runit/runscripts.html#postfix +exec 1>&2 + +daemon_directory=/usr/lib/postfix \ + command_directory=/usr/sbin \ + config_directory=/etc/postfix \ + queue_directory=/var/spool/postfix \ + mail_owner=postfix \ + setgid_group=postdrop \ + /etc/postfix/postfix-script check || exit 1 + +exec /usr/lib/postfix/master +EORUN + +cat </etc/service/dovecot/run +#!/bin/sh +exec dovecot +EORUN + +cat </etc/service/opendkim/run +#!/bin/sh +exec opendkim -f -x /etc/opendkim.conf -u opendkim -P /var/run/opendkim/opendkim.pid +EORUN + +echo "daemon off;" >> /etc/nginx/nginx.conf +cat </etc/service/nginx/run +#!/bin/sh +exec nginx +EORUN + +cat </etc/service/php-fastcgi/run +#!/bin/bash +export PHP_FCGI_CHILDREN=4 PHP_FCGI_MAX_REQUESTS=1000 +exec /usr/bin/php-cgi -q -b /tmp/php-fastcgi.www-data.sock -c /etc/php5/cgi/php.ini +EORUN + +for service in $SERVICES; do + chmod a+x /etc/service/$service/run +done + +echo "Your Mail-in-a-Box services are configured." +