Skip to content

Commit 5352210

Browse files
committed
Distroless Docker image with Caddy
0 parents  commit 5352210

File tree

8 files changed

+195
-0
lines changed

8 files changed

+195
-0
lines changed

.github/workflows/main.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: CI to Docker Hub
2+
3+
# Controls when the workflow will run
4+
on:
5+
# Triggers the workflow on push request events but only for tags vX.X.X
6+
push:
7+
tags:
8+
- "v*.*.*"
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
13+
jobs:
14+
# This workflow call reusable workflow docker-build
15+
build:
16+
uses: nextail/docker-ubuntu-tini/.github/workflows/docker-build.yml@master
17+
with:
18+
DOCKER_REPOSITORY_NAME: nextail
19+
DOCKER_IMAGE_NAME: distroless-caddy
20+
DOCKER_IMAGE_TAG: latest
21+
secrets: inherit

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# syntax=docker/dockerfile:1.4
2+
# https://github.com/caddyserver/caddy/releases
3+
# https://github.com/caddyserver/caddy-docker/blob/00dd7e57fca3ae2e6fdf9cc08526458fd501db79/2.6/alpine/Dockerfile
4+
ARG CADDY_VERSION=2.6.4
5+
6+
FROM caddy:${CADDY_VERSION}-alpine AS caddy_base
7+
8+
FROM gcr.io/distroless/static-debian12:nonroot as debian_nonroot
9+
LABEL author="Ruben Suarez <[email protected]>"
10+
11+
ENV CADDY_VERSION=v${CADDY_VERSION}
12+
13+
# See https://caddyserver.com/docs/conventions#file-locations for details
14+
ENV XDG_CONFIG_HOME=/config
15+
ENV XDG_DATA_HOME=/data
16+
17+
EXPOSE 80
18+
EXPOSE 443
19+
EXPOSE 443/udp
20+
EXPOSE 2019
21+
22+
COPY --from=caddy_base --chown=nonroot:nonroot /usr/bin/caddy /usr/bin/caddy
23+
COPY --from=caddy_base --chown=nonroot:nonroot /config /config
24+
COPY --from=caddy_base --chown=nonroot:nonroot /data /data
25+
26+
COPY --from=caddy_base --chown=nonroot:nonroot /etc/caddy/Caddyfile /etc/caddy/Caddyfile
27+
COPY --from=caddy_base --chown=nonroot:nonroot /usr/share/caddy/ /usr/share/caddy/
28+
29+
CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Distroless Docker image with Caddy
2+
3+
This is a [Distroless](https://github.com/GoogleContainerTools/distroless) Docker image with [Caddy](https://github.com/caddyserver/caddy) from the [official Docker image](https://github.com/caddyserver/caddy-docker).
4+
5+
## Building
6+
7+
You can build the image like this:
8+
9+
```
10+
#!/usr/bin/env bash
11+
12+
DOCKER_REPOSITORY_NAME="nextail"
13+
DOCKER_IMAGE_NAME="distroless-caddy"
14+
DOCKER_IMAGE_TAG="latest"
15+
16+
# see: https://github.com/docker/buildx/issues/495#issuecomment-761562905
17+
#docker buildx build --platform=linux/amd64,linux/arm64 --no-cache --progress=plain --pull \
18+
docker buildx build --platform=linux/amd64,linux/arm64 --no-cache \
19+
-t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \
20+
--label "maintainer=Ruben Suarez <[email protected]>" \
21+
.
22+
23+
docker buildx build --load \
24+
-t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \
25+
.
26+
```
27+
28+
## Running
29+
30+
You can run the container like this (change --rm with -d if you don't want the container to be removed on stop):
31+
32+
```
33+
#!/usr/bin/env bash
34+
35+
DOCKER_REPOSITORY_NAME="nextail"
36+
DOCKER_IMAGE_NAME="distroless-caddy"
37+
DOCKER_IMAGE_TAG="latest"
38+
39+
prepare_docker_timezone() {
40+
# https://www.waysquare.com/how-to-change-docker-timezone/
41+
ENV_VARS+=" --env=TZ=$(cat /etc/timezone)"
42+
}
43+
44+
prepare_docker_timezone
45+
46+
docker run --rm -it \
47+
--name "${DOCKER_IMAGE_NAME}" \
48+
${ENV_VARS} \
49+
"${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" "$@"
50+
```
51+
52+
## Stop
53+
54+
You can stop the running container like this:
55+
56+
```
57+
#!/usr/bin/env bash
58+
59+
DOCKER_IMAGE_NAME="distroless-caddy"
60+
61+
docker stop \
62+
"${DOCKER_IMAGE_NAME}"
63+
```
64+
65+
## Start
66+
67+
If you run the container without --rm you can start it again like this:
68+
69+
```
70+
#!/usr/bin/env bash
71+
72+
DOCKER_IMAGE_NAME="distroless-caddy"
73+
74+
docker start \
75+
"${DOCKER_IMAGE_NAME}"
76+
```
77+
78+
## Remove
79+
80+
If you run the container without --rm you can remove once stopped like this:
81+
82+
```
83+
#!/usr/bin/env bash
84+
85+
DOCKER_IMAGE_NAME="distroless-caddy"
86+
87+
docker rm \
88+
"${DOCKER_IMAGE_NAME}"
89+
```
90+
91+
## For more information
92+
93+
See official [Caddy Docker image documentation](https://hub.docker.com/_/caddy).

build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
DOCKER_REPOSITORY_NAME="nextail"
4+
DOCKER_IMAGE_NAME="distroless-caddy"
5+
DOCKER_IMAGE_TAG="latest"
6+
7+
# see: https://github.com/docker/buildx/issues/495#issuecomment-761562905
8+
#docker buildx build --platform=linux/amd64,linux/arm64 --no-cache --progress=plain --pull \
9+
docker buildx build --platform=linux/amd64,linux/arm64 --no-cache \
10+
-t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \
11+
--label "maintainer=Ruben Suarez <[email protected]>" \
12+
.
13+
14+
docker buildx build --load \
15+
-t "${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \
16+
.

connect.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
DOCKER_IMAGE_NAME="distroless-caddy"
4+
5+
docker exec -it \
6+
"${DOCKER_IMAGE_NAME}" \
7+
bash -l

run.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
DOCKER_REPOSITORY_NAME="nextail"
4+
DOCKER_IMAGE_NAME="distroless-caddy"
5+
DOCKER_IMAGE_TAG="latest"
6+
7+
prepare_docker_timezone() {
8+
# https://www.waysquare.com/how-to-change-docker-timezone/
9+
ENV_VARS+=" --env=TZ=$(cat /etc/timezone)"
10+
}
11+
12+
prepare_docker_timezone
13+
14+
docker run --rm -it \
15+
--name "${DOCKER_IMAGE_NAME}" \
16+
${ENV_VARS} \
17+
"${DOCKER_REPOSITORY_NAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" "$@"

start.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
DOCKER_IMAGE_NAME="distroless-caddy"
4+
5+
docker start \
6+
"${DOCKER_IMAGE_NAME}"

stop.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
DOCKER_IMAGE_NAME="distroless-caddy"
4+
5+
docker stop \
6+
"${DOCKER_IMAGE_NAME}"

0 commit comments

Comments
 (0)