Fake Time in Docker

What if you need a container to have a different time than its host? Well, LD_PRELOAD has a solution for you. While this solution generally works outside of Docker, I rarely find myself outside of a container these days. I like that it works in one without requiring special privileges.

Dockerfile:

FROM ubuntu:latest

RUN apt-get update --fix-missing
RUN DEBIAN_FRONTEND=noninteractive apt-get install git build-essential -y
RUN git clone https://github.com/wolfcw/libfaketime.git
WORKDIR /libfaketime/src
RUN make install
RUN echo "/usr/local/lib/faketime/libfaketime.so.1" > /etc/ld.so.preload

ENTRYPOINT bash

Build with:

docker build -t faketime .

Run with:

docker run -ti --rm -e FAKETIME="1970-01-01 00:00:00" --name faketime faketime

Of course you can run the “date” command to confirm, but this fake time percolates to all processes in the container. I was reminded of the existence of LD_PRELOAD to hijack system calls recently, and remembered this old trick I had stashed in my notes.

And just in case it goes away, I mirrored the excellent repo this is based on here.

Oldie but Goodie

Since I figured out how to emulate old Dos games to host Capture the Flag using JSDos, I might as well spread further other games which left an impression in their time. I don’t mean to compete with the highly curated abandonware sites out there, I just want to reduce the chances for attrition by hosting another copy, and I like having these gems at my fingertips too.

Introducing MadTV, an addictive game where one runs programming for a TV channel. The issue? You’re also trying to “get the girl”, and she only likes utterly boring documentaries which aren’t good for ratings.

Click to pop out