mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2026-03-26 19:27:23 +01:00
more dockerization work
[From @joshdata: This is part of @toilal's work in #377 and 1eb77c332b. The changes are:
* Separates out the runit configuration from starting Mail-in-a-Box setup so that Mail-in-a-Box setup does not block the starting of runit services and we can assume that runit is running during setup (i.e. we can restart services).
* Adds a SKIP_INSTALL flag so that the container can be restarted without re-running the whole Mail-in-a-Box setup.
* Made containers/docker/run more flexible.
* I'm also adding some "|| exit 0"s to the run script to stop if there are any docker errors.
* I'm also adding the prereqs installs from questions.sh into Dockerfile so we don't have to reinstall each time.
]
This commit is contained in:
@@ -3,75 +3,112 @@
|
||||
# ==================================================================
|
||||
#
|
||||
# Run this script from the base directory of the Mail-in-a-Box
|
||||
# repository (i.e. run as 'containers/docker/run').
|
||||
# repository (i.e. run as './containers/docker/run').
|
||||
#
|
||||
# Set these optional environment variables as needed:
|
||||
# * HOST_HTTP_PORT: Host http: port to bind (default: 80).
|
||||
# * HOST_HTTPS_PORT: Host https: port to bind (default: 443).
|
||||
# * SKIP_BUILD: Skip the build of docker image (default: unset).
|
||||
# * NODNS: Skip mapping of DNS ports (53 tcp/upd). They are not always available on host, as another DNS server can be running (default: unset).
|
||||
# * CONTAINER_NAME: Name of the main container (default: mailinabox).
|
||||
# * CONTAINER_DATA_NAME: Name of the data container (default: mailinabox-data).
|
||||
# * NONINTERACTIVE: Use this when mailinabox is already installed on the volume container. Else, it's not recommanded (default: unset).
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# A mailinabox-userdata container is started next. This container
|
||||
# A mailinabox-data container is created next. This container
|
||||
# contains nothing but a shared volume for storing user data.
|
||||
# It is segregated from the rest of the live system to make backups
|
||||
# easier.
|
||||
#
|
||||
# The mailinabox-services container is started last. It is the
|
||||
# The mailinabox container is started last. It is the
|
||||
# real thing: it runs the mailinabox image. This container will
|
||||
# initialize itself and will initialize the mailinabox-userdata
|
||||
# initialize itself and will initialize the mailinabox-data
|
||||
# volume if the volume is new.
|
||||
|
||||
# Build or rebuild the image.
|
||||
# Rebuilds are very fast.
|
||||
|
||||
tput setaf 2
|
||||
echo "Building/updating base image (mailinabox)..."
|
||||
tput setaf 7
|
||||
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}
|
||||
|
||||
docker build -q -t mailinabox .
|
||||
|
||||
if ! docker ps -a | grep mailinabox-userdata > /dev/null; then
|
||||
if [ -z "$SKIP_BUILD" ]; then
|
||||
tput setaf 2
|
||||
echo
|
||||
echo "Creating a new container for your data (mailinabox-userdata)..."
|
||||
echo "Building/updating base image (mailinabox)..."
|
||||
tput setaf 7
|
||||
|
||||
docker run -d \
|
||||
--name mailinabox-userdata \
|
||||
docker build -q -t mailinabox . || exit 1
|
||||
fi;
|
||||
|
||||
if ! docker inspect ${CONTAINER_DATA_NAME} > /dev/null; then
|
||||
tput setaf 2
|
||||
echo
|
||||
echo "Creating a new container for your data (${CONTAINER_DATA_NAME})..."
|
||||
tput setaf 7
|
||||
|
||||
docker create \
|
||||
--name ${CONTAINER_DATA_NAME} \
|
||||
-v /home/user-data \
|
||||
scratch /bin/does-not-exist-but-thats-ok
|
||||
phusion/baseimage:0.9.16 || exit 1
|
||||
else
|
||||
tput setaf 2
|
||||
echo
|
||||
echo "Using existing container mailinabox-userdata for your data."
|
||||
echo "Using existing container ${CONTAINER_DATA_NAME} for your data."
|
||||
tput setaf 7
|
||||
fi
|
||||
|
||||
# End a running container.
|
||||
|
||||
if docker ps -a | grep mailinabox-services > /dev/null; then
|
||||
if docker inspect ${CONTAINER_NAME} > /dev/null; then
|
||||
tput setaf 2
|
||||
echo
|
||||
echo "Destroying mailinabox-services container..."
|
||||
echo "Destroying ${CONTAINER_NAME} container..."
|
||||
tput setaf 7
|
||||
|
||||
docker rm -f mailinabox-services
|
||||
docker rm -f ${CONTAINER_NAME}
|
||||
fi
|
||||
|
||||
# Start container.
|
||||
|
||||
tput setaf 2
|
||||
echo
|
||||
echo "Starting new container (mailinabox-services)..."
|
||||
echo "Starting new container (${CONTAINER_NAME})..."
|
||||
tput setaf 7
|
||||
|
||||
# Run the services container
|
||||
# detached if NONINTERACTIVE is set,
|
||||
# interactively if NONINTERACTIVE is not set,
|
||||
# Notes:
|
||||
# * Passing through SKIP_NETWORK_CHECKS makes it easier to do testing
|
||||
# on a residential network.
|
||||
|
||||
# * --privileged flag cause an issue with bind9/named failing to start in this case
|
||||
# see docker/docker#7318
|
||||
docker run \
|
||||
--privileged \
|
||||
-v /dev/urandom:/dev/random \
|
||||
-p 25 -p 53/udp -p 53/tcp -p 80 -p 443 -p 587 -p 993 \
|
||||
--name mailinabox-services \
|
||||
--volumes-from mailinabox-userdata \
|
||||
-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 \
|
||||
-e "IS_DOCKER=1" \
|
||||
-e "SKIP_NETWORK_CHECKS=$SKIP_NETWORK_CHECKS" \
|
||||
mailinabox
|
||||
mailinabox \
|
||||
|| exit 1
|
||||
|
||||
if [ -z "$NONINTERACTIVE" ]; then
|
||||
tput setaf 2
|
||||
echo
|
||||
echo "Restarting container ${CONTAINER_NAME}..."
|
||||
tput setaf 7
|
||||
|
||||
docker restart ${CONTAINER_NAME} || exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user