Dockerfile
FROM node:8
WORKDIR /
RUN git clone https://github.com/wolfcw/libfaketime.git
WORKDIR /libfaketime/src
RUN make install
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install
COPY . .
CMD ["/bin/sh", "-c", "LD_PRELOAD=/usr/local/lib/faketime/libfaketime.so.1 FAKETIME_NO_CACHE=1 faketime -f '@2017-01-01 00:00:00' npm start"]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
index.js
console.log('modified time', new Date()) // modified time 2017-01-01T00:00:00.052Z
setTimeout(() => {
console.log('end time', new Date()) // end time 2017-01-01T00:00:01.058Z
}, 1e3)
1
2
3
4
5
2
3
4
5
CMD ["/bin/sh", "-c", "LD_PRELOAD=/usr/local/lib/faketime/libfaketime.so.1 FAKETIME_NO_CACHE=1 python /srv/intercept/manage.py runserver 0.0.0.0:3000] os.environ["FAKETIME"] = "2020-01-01"