|
| 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). |
0 commit comments