cloudflare / cloudflared

Cloudflare Tunnel client (formerly Argo Tunnel)

Home Page:https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🐛Change Timezone in Docker

Letgamer opened this issue · comments

Describe the bug
The Docker container has tzdata installed and timezone set, but cloudflared logs show ETC standard time

To Reproduce
Steps to reproduce the behavior:

  1. Use the following Dockerfile
# Stage 1: Build container

# Use a specific Golang version and Alpine Linux as the base image
FROM --platform=linux/amd64 golang:1.20-alpine AS build

# Set the working directory for the build
WORKDIR /src

# Install necessary dependencies for building
RUN apk --no-cache add git build-base curl jq

RUN apk --no-cache -U add tzdata
RUN ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime

# Fetch the latest release version using GitHub API
RUN VERSION=$(curl -s https://api.github.com/repos/cloudflare/cloudflared/releases/latest | jq -r .tag_name) \
    && git clone https://github.com/cloudflare/cloudflared --depth=1 --branch ${VERSION} .

# Build the cloudflared binary for Linux amd64
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make cloudflared

# Stage 3: Runtime container
FROM alpine

# Set the working directory in the new image
WORKDIR /

# Copy the built cloudflared binary and required files
COPY --from=build /src/cloudflared .
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

# Copy curl binary from a docker image
COPY --from=ghcr.io/tarampampam/curl /bin/curl /bin/curl

RUN apk --no-cache -U add tzdata
RUN ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime

# Set environment variable for the cloudflared origin certificate
ENV TUNNEL_ORIGIN_CERT=/etc/cloudflared/cert.pem

# Specify the entry point and default command for the container
ENTRYPOINT ["/cloudflared", "--no-autoupdate"]
CMD ["version"]
  1. And the following docker-compose file
version: "3.9"

services:

  tunnel:
    build:
      context: .
      dockerfile: Dockerfile
    image: cloudflared:custom
    container_name: tunnel
    restart: always
    command: tunnel --metrics 0.0.0.0:3333 run
    environment:
      ## Set timezone
      TZ: ${TZ}
    healthcheck:
        test: ['CMD-SHELL', 'curl --fail http://localhost:3333/ready || exit 1']
    volumes:
      - ./cloudflared:/etc/cloudflared:ro
      - /etc/timezone:/etc/timezone:ro
      #- /etc/localtime:/etc/localtime:ro
    networks:
      - cftunnel-transport
  1. Run docker-compose up --build in the same directory

Expected behavior
Using docker-compose logs in the directory the log timestamp should be using the time set in the alpine container

Environment and versions

  • OS: Linux
  • Architecture: amd64
  • Version: 2023.10.0