DEV Community

davert
davert

Posted on

How to fake time inside Docker container

Let me share a working advice you can use in case you need to jump in time in a Docker container. You may need this for testing purposes, for instance, to test some events in the future.

You will need a Docker Image of the app you need want to launch.

Create Docker file:

FROM my-image
RUN apt update -y && apt install -y faketime
Enter fullscreen mode Exit fullscreen mode

Build a container naming it fake-time:

docker build -t fake-time .
Enter fullscreen mode Exit fullscreen mode

Run new container

docker run fake-time:latest faketime '2030-12-18 19:46:00' ./your-app
Enter fullscreen mode Exit fullscreen mode

Or use it inside docker-compose:

  service:
    image: "fake-time:latest"
    command: "faketime '2030-12-18 19:46:00' ./your-app
Enter fullscreen mode Exit fullscreen mode

Follow me on X for more development tips.

Top comments (0)