Last active
June 13, 2024 20:46
-
-
Save 0187773933/ddd0f05be9fc833dc47b357a98a02300 to your computer and use it in GitHub Desktop.
Cloudflare Tunnel Docker File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sudo docker build --no-cache -t "cloudflared" . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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