-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_start.sh
executable file
·63 lines (47 loc) · 1.73 KB
/
docker_start.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
#!/usr/bin/env sh
# SPDX-FileCopyrightText: © 2024 Sebastian Davids <[email protected]>
# SPDX-License-Identifier: Apache-2.0
set -eu
readonly http_port="${1:-3000}"
readonly tag='local'
# https://docs.docker.com/reference/cli/docker/image/tag/#description
readonly namespace='de.sdavids'
readonly repository='sdavids-docker-healthcheck'
readonly label_group='de.sdavids.docker.group'
readonly label="${label_group}=${repository}"
readonly image_name="${namespace}/${repository}"
readonly container_name='sdavids-docker-healthcheck-rust-http'
readonly host_name='localhost'
readonly network_name="${repository}"
docker network inspect "${network_name}" >/dev/null 2>&1 \
|| docker network create \
--driver bridge "${network_name}" \
--label "${label_group}=${namespace}" >/dev/null
# to ensure ${label} is set, we use --label "${label}"
# which might overwrite the label ${label_group} of the image
docker container run \
--init \
--rm \
--detach \
--security-opt='no-new-privileges=true' \
--cap-add=chown \
--cap-add=setgid \
--cap-add=setuid \
--cap-drop=all \
--network="${network_name}" \
--publish "${http_port}:3000" \
--name "${container_name}" \
--label "${label}" \
"${image_name}:${tag}" >/dev/null
readonly url="http://${host_name}:${http_port}"
printf '\nListen local: %s\n' "${url}"
if command -v pbcopy >/dev/null 2>&1; then
printf '%s' "${url}" | pbcopy
printf '\nThe URL has been copied to the clipboard.\n'
elif command -v xclip >/dev/null 2>&1; then
printf '%s' "${url}" | xclip -selection clipboard
printf '\nThe URL has been copied to the clipboard.\n'
elif command -v wl-copy >/dev/null 2>&1; then
printf '%s' "${url}" | wl-copy
printf '\nThe URL has been copied to the clipboard.\n'
fi