Creating clock skew with docker

2019-08-13 06:00发布

I want to verify the effects of clock skew on a distributed system and the simplest way for me to do that is using multiple docker containers linked together.

Can I modify the clocks from individual docker containers so that they are decoupled from the host machine?

标签: docker
2条回答
狗以群分
2楼-- · 2019-08-13 06:09

If you want to run a container with a different time, you can launch it with a different timezone, see this extract from https://github.com/docker/docker/issues/3359#issuecomment-32150214

$ docker run --rm busybox date
Thu Mar 20 04:42:02 UTC 2014
$ docker run --rm -v /etc/localtime:/etc/localtime  busybox date
Thu Mar 20 14:42:20 EST 2014
$ FILE=$(mktemp) ; echo $FILE ; echo -e "Europe/Brussels" > $FILE ; docker run --rm -v $FILE:/etc/timezone -v /usr/share/zoneinfo/Europe/Brussels:/etc/localtime busybox date
/tmp/tmp.JwL2A9c50i
Thu Mar 20 05:42:26 CET 2014
查看更多
The star\"
3楼-- · 2019-08-13 06:24

I'm not sure that linked answer is entirely appropriate.

The simple fact is that containers are just processes: you can't do anything inside a container that you can't do in a normal subprocess. You can muck about with timezones and such, but they are still referencing the same kernel clock as anything else.

If you really want to play with time skew, you will probably need to investigate some sort of virtualization solution.

查看更多
登录 后发表回答