cloudflared Docker & Self-Hosted Deployment

GitHub

Go cloudflare-tunnel & reverse-proxy repository by @cloudflare. AI agent rules & system prompts with 16k stars.

16,459 stars Go Go 1 file ยท ~2,391 tokens #cloudflare#cloudflare-tunnel#reverse-proxy#zero-trust-network-access
1. Pull Image (DOCKERHUB) docker pull cloudflare/cloudflared:latest
2. Docker Run (1-Click Launch) docker run -d --name cloudflared --restart always cloudflare/cloudflared:latest
3. Podman Run podman run -d --name cloudflared --restart always cloudflare/cloudflared:latest
4. Skopeo Inspect (Zero-Pull Manifest) skopeo inspect docker://docker.io/cloudflare/cloudflared:latest
5. ORAS Pull (OCI Artifact) oras pull cloudflare/cloudflared:latest
Dockerfile
# use a builder image for building cloudflare
ARG TARGET_GOOS
ARG TARGET_GOARCH
FROM golang:1.27.4 AS builder
ARG TARGET_GOOS
ARG TARGET_GOARCH
ARG GOPROXY=https://athens.cfdata.org|https://proxy.golang.org|direct
ENV GO111MODULE=on \
  CGO_ENABLED=0 \
  GOPROXY=${GOPROXY} \
  TARGET_GOOS=${TARGET_GOOS} \
  TARGET_GOARCH=${TARGET_GOARCH} \
  # the CONTAINER_BUILD envvar is used set github.com/cloudflare/cloudflared/metrics.Runtime=virtual
  # which changes how cloudflared binds the metrics server
  CONTAINER_BUILD=1


WORKDIR /go/src/github.com/cloudflare/cloudflared/

# Download dependencies in their own layer so source-only changes reuse it.
COPY go.mod go.sum ./
RUN go mod download

COPY . .

# compile cloudflared
RUN make cloudflared

# use a distroless base image with glibc
FROM gcr.io/distroless/base-debian13:nonroot@sha256:83e67481ae9fc8c7a6d211113431fb8085619bed49672e583261111bac184f0d

LABEL org.opencontainers.image.source="https://github.com/cloudflare/cloudflared"

# copy our compiled binary
COPY --from=builder --chown=nonroot /go/src/github.com/cloudflare/cloudflared/cloudflared /usr/local/bin/

# run as nonroot user
# We need to use numeric user id's because Kubernetes doesn't support strings:
# https://github.com/kubernetes/kubernetes/blob/v1.33.2/pkg/kubelet/kuberuntime/security_context_others.go#L49
# The `nonroot` user maps to `65532`, from: https://github.com/GoogleContainerTools/distroless/blob/main/common/variables.bzl#L18
USER 65532:65532

# disable autoupdate: images are updated by pulling a new tag, not by replacing the binary in place.
# set as an env var rather than an entrypoint flag, so it still applies when the entrypoint is overridden.
ENV NO_AUTOUPDATE=true

# command / entrypoint of container
ENTRYPOINT ["cloudflared"]
CMD ["version"]