mirror of
				https://github.com/mail-in-a-box/mailinabox.git
				synced 2025-11-03 19:30:54 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			110 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			110 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/bin/bash
 | 
						|
# Use this script to launch Mail-in-a-Box within a docker container.
 | 
						|
# ==================================================================
 | 
						|
#
 | 
						|
# Run this script from the base directory of the Mail-in-a-Box
 | 
						|
# repository (i.e. run as 'containers/docker/run').
 | 
						|
#
 | 
						|
# 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
 | 
						|
# 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
 | 
						|
# real thing: it runs the mailinabox image. This container will
 | 
						|
# initialize itself and will initialize the mailinabox-userdata
 | 
						|
# volume if the volume is new.
 | 
						|
 | 
						|
# Build or rebuild the image.
 | 
						|
# Rebuilds are very fast.
 | 
						|
 | 
						|
HOST_HTTP_PORT=${HOST_HTTP_PORT:-80}
 | 
						|
HOST_HTTPS_PORT=${HOST_HTTPS_PORT:-443}
 | 
						|
HOST_USERDATA_VOLUME=${HOST_USERDATA_VOLUME:-/home/user-data}
 | 
						|
 | 
						|
tput setaf 2
 | 
						|
echo "Building/updating base image (mailinabox)..."
 | 
						|
tput setaf 7
 | 
						|
 | 
						|
docker build -q -t mailinabox .
 | 
						|
 | 
						|
if ! docker ps -a | grep mailinabox-userdata > /dev/null; then
 | 
						|
	tput setaf 2
 | 
						|
	echo
 | 
						|
	echo "Creating a new container for your data (mailinabox-userdata)..."
 | 
						|
	tput setaf 7
 | 
						|
 | 
						|
	docker run -d \
 | 
						|
		--name mailinabox-userdata \
 | 
						|
		-v $HOST_USERDATA_VOLUME:/home/user-data \
 | 
						|
		phusion/baseimage:0.9.16
 | 
						|
else
 | 
						|
	tput setaf 2
 | 
						|
	echo
 | 
						|
	echo "Using existing container mailinabox-userdata for your data."
 | 
						|
	tput setaf 7
 | 
						|
fi
 | 
						|
 | 
						|
# End a running container.
 | 
						|
 | 
						|
if docker ps -a | grep mailinabox-services > /dev/null; then
 | 
						|
	tput setaf 2
 | 
						|
	echo
 | 
						|
	echo "Destroying mailinabox-services container..."
 | 
						|
	tput setaf 7
 | 
						|
 | 
						|
	docker rm -f mailinabox-services
 | 
						|
fi
 | 
						|
 | 
						|
# Start container.
 | 
						|
 | 
						|
tput setaf 2
 | 
						|
echo
 | 
						|
echo "Starting new container (mailinabox-services)..."
 | 
						|
tput setaf 7
 | 
						|
 | 
						|
# Run the services container detached.
 | 
						|
# 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 \
 | 
						|
	-v /dev/urandom:/dev/random \
 | 
						|
	-p 25:25 \
 | 
						|
	-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 mailinabox-services \
 | 
						|
	--volumes-from mailinabox-userdata \
 | 
						|
	-e "SKIP_NETWORK_CHECKS=$SKIP_NETWORK_CHECKS" \
 | 
						|
	-d \
 | 
						|
	-t \
 | 
						|
	mailinabox
 | 
						|
 | 
						|
tput setaf 2
 | 
						|
echo
 | 
						|
echo "Initializing container (mailinabox-services)..."
 | 
						|
tput setaf 7
 | 
						|
 | 
						|
# run init.sh
 | 
						|
docker exec \
 | 
						|
	-it \
 | 
						|
	mailinabox-services \
 | 
						|
	/usr/local/mailinabox/containers/docker/init.sh
 | 
						|
 | 
						|
tput setaf 2
 | 
						|
echo
 | 
						|
echo "Restarting container..."
 | 
						|
tput setaf 7
 | 
						|
 | 
						|
docker restart mailinabox-services
 |