Skip to content

Instantly share code, notes, and snippets.

@0187773933
Last active June 13, 2024 20:46
Show Gist options
  • Save 0187773933/ddd0f05be9fc833dc47b357a98a02300 to your computer and use it in GitHub Desktop.
Save 0187773933/ddd0f05be9fc833dc47b357a98a02300 to your computer and use it in GitHub Desktop.
Cloudflare Tunnel Docker File
FROM alpine:latest
# Config
ENV GO111MODULE=on
ENV CGO_ENABLED=0
ARG GOOS="linux"
ARG GOARCH="arm64"
# Install
RUN apk --update --no-cache add git
RUN apk --update --no-cache add go
# Setup Go
ENV GO_VERSION=1.22.3
ENV GO_DOWNLOAD_URL=https://golang.org/dl/go$GO_VERSION.linux-amd64.tar.gz
ENV GO_INSTALL_DIR=/usr/local/go
RUN apk update && \
apk add --no-cache bash curl gcc musl-dev openssl
RUN curl -Lo go.tgz $GO_DOWNLOAD_URL && \
tar -C /usr/local -xzf go.tgz && \
rm go.tgz
ENV PATH=$GO_INSTALL_DIR/bin:$PATH
RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin
# Pull And Build Cloudflared
WORKDIR /src
RUN git clone https://github.com/cloudflare/cloudflared
WORKDIR /src/cloudflared
RUN VERSION=$(git describe --tags --always --match "[0-9][0-9][0-9][0-9].*.*"); \
GOOS=GOOS GOARCH=GOARCH CGO_ENABLED=0 \
go build -v -mod=vendor -ldflags="-X main.Version=$VERSION" github.com/cloudflare/cloudflared/cmd/cloudflared
# Setup User
ARG GROUP_NAME="nonsudo"
ARG USERNAME="nonsudo"
RUN addgroup $GROUP_NAME
RUN adduser -s /bin/bash -h /home/$USERNAME -D --uid 33333 --ingroup $GROUP_NAME $USERNAME
USER $USERNAME
ENTRYPOINT [ "/src/cloudflared/cloudflared" , "--no-autoupdate" ]
#!/bin/bash
sudo docker build --no-cache -t "cloudflared" .
#!/bin/bash
APP_NAME="cloudflared"
TOKEN="asdfasdfasdfsadfasdfasdfasdf"
sudo docker rm $APP_NAME -f || echo "failed to remove existing $APP_NAME server"
id=$(sudo docker run -dit --restart='always' \
--name $APP_NAME \
--net="host" \
$APP_NAME tunnel run --token=$TOKEN --protocol=http2)
echo "ID = $id"
sudo docker logs -f "$id"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment