2014-08-17 12:48:27 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Use this script to launch Mail-in-a-Box within a docker container.
|
|
|
|
# ==================================================================
|
|
|
|
#
|
2015-01-30 22:40:58 +00:00
|
|
|
# Run this script from the base directory of the Mail-in-a-Box
|
|
|
|
# repository (i.e. run as 'containers/docker/run').
|
|
|
|
#
|
2014-08-17 12:48:27 +00:00
|
|
|
# A base image is created first. The base image installs Ubuntu
|
|
|
|
# packages and pulls in the Mail-in-a-Box source code. This is
|
|
|
|
# defined in Dockerfile at the root of this repository.
|
|
|
|
#
|
2015-04-04 15:50:16 +00:00
|
|
|
# A mailinabox-data container is created next. This container
|
2014-08-17 12:48:27 +00:00
|
|
|
# contains nothing but a shared volume for storing user data.
|
|
|
|
# It is segregated from the rest of the live system to make backups
|
|
|
|
# easier.
|
|
|
|
#
|
2015-04-04 15:50:16 +00:00
|
|
|
# The mailinabox container is started last. It is the
|
2014-08-17 12:48:27 +00:00
|
|
|
# real thing: it runs the mailinabox image. This container will
|
2015-04-04 15:50:16 +00:00
|
|
|
# initialize itself and will initialize the mailinabox-data
|
2014-08-17 12:48:27 +00:00
|
|
|
# volume if the volume is new.
|
|
|
|
|
|
|
|
# Build or rebuild the image.
|
|
|
|
# Rebuilds are very fast.
|
|
|
|
|
2015-04-04 15:50:16 +00:00
|
|
|
HOST_HTTP_PORT=${HOST_HTTP_PORT:-80}
|
|
|
|
HOST_HTTPS_PORT=${HOST_HTTPS_PORT:-443}
|
|
|
|
CONTAINER_NAME=${CONTAINER_NAME:-mailinabox}
|
|
|
|
CONTAINER_DATA_NAME=${CONTAINER_DATA_NAME:-${CONTAINER_NAME}-data}
|
2015-01-30 22:40:58 +00:00
|
|
|
|
2015-04-04 15:50:16 +00:00
|
|
|
if [ -z "$SKIP_BUILD" ]; then
|
|
|
|
tput setaf 2
|
|
|
|
echo "Building/updating base image (mailinabox)..."
|
|
|
|
tput setaf 7
|
2015-01-30 22:40:58 +00:00
|
|
|
|
2015-04-04 15:50:16 +00:00
|
|
|
docker build -q -t mailinabox .
|
|
|
|
fi;
|
|
|
|
|
|
|
|
if ! docker inspect ${CONTAINER_DATA_NAME} > /dev/null; then
|
2015-01-30 22:40:58 +00:00
|
|
|
tput setaf 2
|
|
|
|
echo
|
2015-04-04 15:50:16 +00:00
|
|
|
echo "Creating a new container for your data (${CONTAINER_DATA_NAME})..."
|
2015-01-30 22:40:58 +00:00
|
|
|
tput setaf 7
|
|
|
|
|
2015-04-04 15:50:16 +00:00
|
|
|
docker create \
|
|
|
|
--name ${CONTAINER_DATA_NAME} \
|
|
|
|
$([ -z "$HOST_USERDATA_VOLUME" ] && echo "-v $HOST_USERDATA_VOLUME:/home/user-data" || echo "-v /home/user-data") \
|
|
|
|
phusion/baseimage:0.9.16
|
2015-01-30 22:40:58 +00:00
|
|
|
else
|
|
|
|
tput setaf 2
|
|
|
|
echo
|
2015-04-04 15:50:16 +00:00
|
|
|
echo "Using existing container ${CONTAINER_DATA_NAME} for your data."
|
2015-01-30 22:40:58 +00:00
|
|
|
tput setaf 7
|
2014-08-17 12:48:27 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# End a running container.
|
2015-04-04 15:50:16 +00:00
|
|
|
if docker inspect ${CONTAINER_NAME} > /dev/null; then
|
2015-01-30 22:40:58 +00:00
|
|
|
tput setaf 2
|
|
|
|
echo
|
2015-04-04 15:50:16 +00:00
|
|
|
echo "Destroying ${CONTAINER_NAME} container..."
|
2015-01-30 22:40:58 +00:00
|
|
|
tput setaf 7
|
|
|
|
|
2015-04-04 15:50:16 +00:00
|
|
|
docker rm -f ${CONTAINER_NAME}
|
2014-08-17 12:48:27 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Start container.
|
2015-01-30 22:40:58 +00:00
|
|
|
tput setaf 2
|
|
|
|
echo
|
2015-04-04 15:50:16 +00:00
|
|
|
echo "Starting new container (${CONTAINER_NAME})..."
|
2015-01-30 22:40:58 +00:00
|
|
|
tput setaf 7
|
|
|
|
|
2015-04-04 15:50:16 +00:00
|
|
|
# Run the services container
|
|
|
|
# detached if NONINTERACTIVE is set,
|
|
|
|
# interactively if NONINTERACTIVE is not set,
|
2015-01-30 22:40:58 +00:00
|
|
|
# Notes:
|
|
|
|
# * Passing through SKIP_NETWORK_CHECKS makes it easier to do testing
|
|
|
|
# on a residential network.
|
2015-04-04 15:50:16 +00:00
|
|
|
# * --privileged flag cause an issue with bind9/named failing to start in this case
|
|
|
|
# see docker/docker#7318
|
2015-01-30 22:40:58 +00:00
|
|
|
docker run \
|
2015-01-24 10:29:16 +00:00
|
|
|
-v /dev/urandom:/dev/random \
|
2015-04-04 15:50:16 +00:00
|
|
|
-p 25:25 \
|
|
|
|
$([ -z "$NODNS" ] && echo "-p 53:53/udp -p 53:53/tcp") \
|
|
|
|
-p $HOST_HTTP_PORT:80 \
|
|
|
|
-p $HOST_HTTPS_PORT:443 \
|
|
|
|
-p 587:587 \
|
|
|
|
-p 993:993 \
|
|
|
|
-p 4190:4190 \
|
|
|
|
--name ${CONTAINER_NAME} \
|
|
|
|
--volumes-from ${CONTAINER_DATA_NAME} \
|
|
|
|
--restart always \
|
|
|
|
$([ ! -z "$NONINTERACTIVE" ] && echo "-d") \
|
|
|
|
-it \
|
2015-01-30 22:40:58 +00:00
|
|
|
mailinabox
|
2015-04-04 15:50:16 +00:00
|
|
|
|
|
|
|
if [ -z "$NONINTERACTIVE" ]; then
|
|
|
|
tput setaf 2
|
|
|
|
echo
|
|
|
|
echo "Restarting container ${CONTAINER_NAME}..."
|
|
|
|
tput setaf 7
|
|
|
|
|
|
|
|
docker restart ${CONTAINER_NAME}
|
|
|
|
fi
|