docker: Apline configure timezone

Container docker based on Alpine Linux uses standard timezone UTC, if in your case needed any other timezone you must to follow 2 steps

  1. In docker startup command add environment varialbe -e TZ="Europe/Kiev" (ofc change timezone to your’s). Full line for example.
    docker run --name containername -d \
          -e TZ="Europe/Kiev" \
          nginx:alpine

    But it works only when tzdata package already installed in the image, for example in the nginx image tzdata already installed.

  2. If you build image from clear alpine:latest – you need to install tzdata, here are example of Dockerfile
    FROM alpine:latest
    
    RUN apk update && \
        apk add --no-cache tzdata
    
    ENTRYPOINT ["date"]
    

    An example of production Dockerfile, based on python image that used alpine for my flask application, here I installing some requirements and tzdata.

    FROM python:3.7-alpine
    
    WORKDIR /home/app
    COPY app app
    COPY migrations migrations
    COPY config.py requirements.txt run.py run.sh ./
    
    RUN python -m venv venv
    
    RUN apk update && \
        apk add --no-cache --virtual build-deps gcc python3-dev musl-dev postgresql-dev && \
        apk add --no-cache postgresql-dev tzdata && \
        venv/bin/pip install --no-cache-dir psycopg2-binary gunicorn && \
        apk del --no-cache build-deps
    
    RUN venv/bin/pip install -r requirements.txt
    
    
    RUN chmod +x run.sh
    ENV FLASK_APP run.py
    EXPOSE 5000
    
    ENTRYPOINT ["./run.sh"]
    

     

Leave a Reply

Your email address will not be published. Required fields are marked *