-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_docker_container.sh
executable file
·79 lines (71 loc) · 2.59 KB
/
setup_docker_container.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# Description: Docker container (webserver) setup script, that will setup a container with a default folder structure, file permissions, selinux context and a compose file.
# Author: Sanjay kumar Srikakulam
# Changelog:
# 26-05-2017 Init
usage() {
echo ""
echo "Usage: $0 <OPTIONS>"
echo "Required Parameters:"
echo "-p <path> Provide a path to create the container"
echo "-d <directory_name> Provide a name for the container directory"
echo "Optional Parameters:"
echo "-c <container_name> Provide a name for the container"
echo "Example:"
echo "./setup_docker_container.sh -p <> -d <> -c <>"
exit 1
}
while getopts ":p:d:c:" i; do
case "${i}" in
p)
path=$OPTARG
;;
d)
directory_name=$OPTARG
;;
c)
container_name=$OPTARG
;;
esac
done
if [[ "$path" == "" || "$directory_name" == "" ]] ; then
usage
fi
if [[ "$container_name" == "" ]] ; then
container_name=$directory_name
fi
# Creates the default folder structure
if [[ -d "$path" ]] ; then
mkdir -p $path/$directory_name/{extra-conf.d,apache-log,certs,htdocs}
fi
# Setup the default selinux context exclusively for the above created sub-directories
chcon system_u:object_r:container_share_t:s0 "$path/$directory_name/extra-conf.d"
chcon system_u:object_r:container_share_t:s0 "$path/$directory_name/apache-log"
chcon system_u:object_r:container_share_t:s0 "$path/$directory_name/certs"
chcon system_u:object_r:container_share_t:s0 "$path/$directory_name/htdocs"
# Creates a default compose file with required selinux contexts for "Volumes"
touch "$path/$directory_name/docker-compose.yml" ; chmod +x "$path/$directory_name/docker-compose.yml"
echo "version: '2'
services:
apache:
image: docker.io/sanjaysrikakulam/alpine-apache:latest
restart: unless-stopped
container_name: $container_name
hostname: <Please add the hostname name here>
ports:
- \"80\"
- \"443\"
cap_add:
- NET_ADMIN
- NET_RAW
volumes:
- ./extra-conf.d:/etc/apache2/extra-conf.d:ro
- ./htdocs:/var/www/htdocs:Z
- ./certs:/etc/ssl/apache2:ro
- ./apache-log:/var/www/logs:Z
environment:
SERVER_NAME: <Please add the Server name here>
REDIRECT_HTTP_TO_HTTPS : \"true\"
ENABLE_HSTS: \"true\"
ENABLE_MOD_PROXY: \"true\"
" > $path/$directory_name/docker-compose.yml