Initial version of modjular-ubuntu.

parents
#!/bin/bash
HOST_IP=$(/sbin/ip route|awk '/default/ { print $3 }')
echo "$HOST_IP host.docker.internal" >> /etc/hosts
FROM nginx:1.19.3
LABEL maintainer="Jeffrey Phillips Freeman the@jeffreyfreeman.me"
# Install needed tools
RUN apt-get update && \
apt-get upgrade -y --no-install-recommends && \
apt-get dist-upgrade -y --no-install-recommends && \
apt-get install -y --no-install-recommends \
iproute2 \
gawk && \
apt-get clean && \
rm -r /var/lib/apt/lists/*
# Define the nginx user as www-data
RUN sed -i 's/^[[:space:]]*user[[:space:]]*[a-zA-Z]*/user www-data/g' /etc/nginx/nginx.conf
COPY docker-entrypoint.sh /docker-entrypoint.sh
COPY 30-add-host-ip-entry.sh /docker-entrypoint.d/30-add-host-ip-entry.sh
COPY docker-run.sh /docker-run.sh
RUN mkdir -p /docker-run.d
COPY nginx-run.sh /docker-run.d/nginx-run.sh
ENTRYPOINT [ "/docker-entrypoint.sh" ]
CMD [ "/docker-run.sh" ]
version: '2'
services:
modular-nginx:
build: .
image: modjular/modjular-nginx:latest
#!/bin/bash
set -e
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
exec 3>&1
else
exec 3>/dev/null
fi
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
echo >&3 "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
find "/docker-entrypoint.d/" -follow -type f -print | sort -n | while read -r f; do
case "$f" in
*.sh)
if [ -x "$f" ]; then
echo >&3 "$0: Launching $f";
"$f"
else
# warn on shell scripts without exec bit
echo >&3 "$0: Ignoring $f, not executable";
fi
;;
*) echo >&3 "$0: Ignoring $f";;
esac
done
echo >&3 "$0: Configuration complete; ready for start up"
else
echo >&3 "$0: No files found in /docker-entrypoint.d/, skipping configuration"
fi
exec "$@"
#!/bin/bash
# SIGTERM-handler
term_handler() {
for PID in "${PIDS[@]}"
do
[[ -n "$PID" ]] && kill "$PID"
done
exit 0
}
trap 'term_handler' INT QUIT TERM
set -e
# Run all the scripts in the docker-run.d directory. If a script stopping should stop the container then
# the script should export its PID in the PID variable, otherwise it should not export the variable.
PIDS=()
if /usr/bin/find "/docker-run.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
echo >&3 "$0: /docker-run.d/ is not empty, will attempt to bring up services"
echo >&3 "$0: Looking for shell scripts in /docker-run.d/"
for f in $(ls /docker-run.d/* | sort -n)
do
case "$f" in
*.sh)
if [ -x "$f" ]; then
echo >&3 "$0: Launching $f";
unset PID
source $f
PIDS+=( "${PID}" )
else
# warn on shell scripts without exec bit
echo >&3 "$0: Ignoring $f, not executable";
fi
;;
*) echo >&3 "$0: Ignoring $f";;
esac
done
echo >&3 "$0: Start up complete, all services are now running."
else
echo >&3 "$0: No files found in /docker-run.d/, nothing to do, exiting!"
exit 0
fi
# Run indefinately until one of the running processes stops
ALL_RUNNING="true"
while [[ "$ALL_RUNNING" == "true" ]]; do
sleep 1
for PID in "${PIDS[@]}"
do
if [[ ! -e /proc/$PID ]]; then
ALL_RUNNING="false"
echo "One of the processes shutdown: ${PID}"
fi
done
done
# Stop container properly
term_handler
echo "Running nginx..."
nginx -g "daemon off;" &
export PID="$!"
echo "...nginx is now running: ${PID}"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment