Adam Yao
Adam Yao

Reputation: 181

postgres docker contanner on raspberrypi time aways wrong

postgresql on my rasbian aways have got wrong time!

but not the same with nginx contanner,

what's wrong with my docker?

Nginx:

pi@raspberrypi:~$ docker run -it -e TZ=Asia/Shanghai nginx date
Mon Oct 25 14:12:45 CST 2021

Postgres:

pi@raspberrypi:~$ docker run -it postgres:alpine date
Tue Jun 30 15:19:12 UTC 2071

Postgres localtime:

pi@raspberrypi:~$ docker run -it -e TZ=Asia/Shanghai -v /etc/localtime:/etc/localtime:ro postgres:12 date
Thu 01 Jan 1970 08:00:00 AM CST

My docker info below:


pi@raspberrypi:~$ docker version
Client: Docker Engine - Community
 Version:           20.10.9
 API version:       1.41
 Go version:        go1.16.8
 Git commit:        c2ea9bc
 Built:             Mon Oct  4 16:06:55 2021
 OS/Arch:           linux/arm
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.9
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.8
  Git commit:       79ea9d3
  Built:            Mon Oct  4 16:04:47 2021
  OS/Arch:          linux/arm
  Experimental:     false
 containerd:
  Version:          1.4.11
  GitCommit:        5b46e404f6b9f661a205e28d59c982d3634148f8
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Upvotes: 4

Views: 456

Answers (1)

Andrew Rau
Andrew Rau

Reputation: 41

It appears to be an issue with the libseccomp2 library on Raspberry Pi. I was experiencing the same issues, and eventually resolved it by following the steps in this thread

Add the following to /etc/apt/sources.list:

deb http://raspbian.raspberrypi.org/raspbian/ testing main

Run apt update

Run apt-get install libseccomp2/testing

After running these updates the date/time should reflect that of your host. You may need to also mount /etc/localtime and /etc/timezone to get everything to match.

docker run -it -v /etc/timezone:/etc/timezone:ro -v /etc/localtime:/etc/localtime:ro --entrypoint /bin/sh postgres

docker-compose.yml

services:
  db:
    container_name: postgres
    image: postgres:latest
    restart: unless-stopped
    environment:
      TZ: America/Chicago
      PGTZ: America/Chicago
      POSTGRES_DB: test
      POSTGRES_USER: testing
      POSTGRES_PASSWORD: password
    volumes:
      - /etc/localtime:/etc/localtime:ro

Upvotes: 3

Related Questions