Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timezone on boot2docker VM #476

Closed
docwhat opened this issue Aug 7, 2014 · 11 comments
Closed

Fix timezone on boot2docker VM #476

docwhat opened this issue Aug 7, 2014 · 11 comments
Labels

Comments

@docwhat
Copy link

@docwhat docwhat commented Aug 7, 2014

When first bringing up the boot2docker (either init or up) boot2docker should copy (on the Mac, anyway) /etc/localtime to the VM.

This will fix the timezone within the boot2docker VM, which makes trouble shooting certain issues easier.

Example:

# Without /etc/localtime
date +'%I:%M %p %Z' # returns 11:33 PM UTC

# With /etc/localtime (America/New_York)
date +'%I:%M %p %Z' # returns 07:33 PM EDT
@SvenDowideit
Copy link
Contributor

@SvenDowideit SvenDowideit commented Aug 8, 2014

@docwhat true - can you think of circumstances where doing this may be a problem? (I'm worried, but busy elsewhere, so hoping you could list some of the risks :))

@docwhat
Copy link
Author

@docwhat docwhat commented Aug 8, 2014

So the zoneinfo database format is pretty stable, so I don't anticipate any changes that would cause breakage. Also, boot2docker is usually pretty up-to-date so if anything it'll be a newer libc in boot2docker for an older zoneinfo format, which should always work.

Obviously, not all systems have an /etc/localtime file, such as on Windows. But if it exists, it should always be in zoneinfo format.

/etc/localtime is usually a link to /usr/share/zoneinfo/<your timezone>. That link could be broken, but then we could just fall back to whatever we do on windows (e.g. nothing or emit a warning?).

This should be pretty darn safe in the scheme of things.

@sfitts
Copy link

@sfitts sfitts commented Sep 24, 2014

Even on Windows it would be nice if the boot2docker vm had the same timezone as the host machine. It would obviously take more work than copying a file, but it should be doable.

@ARF1
Copy link

@ARF1 ARF1 commented Mar 19, 2017

Is there any movement on this? Is it possible to set a timezone on a Windows boot2docker vm?

@wglambert wglambert added the Issue label Jul 11, 2018
@dxmann73
Copy link

@dxmann73 dxmann73 commented Jul 31, 2018

I guess this only applies to Windows 7 / Docker Toolkit anymore. Anyway, here is how I changed the timezone on my Windows 7 docker machine:

You need to add some permanent settings to the docker machine as per the boot2docker FAQ

  • create /var/lib/boot2docker/bootlocal.sh in the docker machine (to get a shell, hit VirtualBox -> "Show" on the virtual machine)
  • give exec flag chmod u+x bootlocal.sh

As described in the Tiny Core Linux forum and the Wiki

cd /var/lib/boot2docker
tce-fetch.sh tzdata.tcz
mkdir ext
sudo mount tzdata.tcz ext -t squashfs -o loop,ro,bs=4096
# I needed Europe/Berlin; find your timezone by scanning the ./ext directory
cp ext/usr/local/share/zoneinfo/Europe/Berlin ./Europe-Berlin.tz
umount ext
rm -rf ext tzdata.tcz

The file Europe-Berlin.tz should now survive restarts of the docker machine; verify this.

Finally, copy the timezone file when starting up docker-machine by adding the following to the bootlocal.sh script

#!/bin/sh
cp /var/lib/boot2docker/Europe-Berlin.tz /etc/localtime

You should see the correct time now when you enter date

@michelcve
Copy link

@michelcve michelcve commented Nov 22, 2018

With the 17,9 branch this no longer works, as the squashfs kernel module is missing.

The kernel option CONFIG_SQUASHFS=m is no longer set in 17.9 :-(

Should we do this differently in 17.9, or is this a 'bug' and should the squashfs module be brought back?

@tianon
Copy link
Contributor

@tianon tianon commented Nov 22, 2018

Doh, definitely unintentional -- I'll make a PR to add that back now. 👍

@tianon
Copy link
Contributor

@tianon tianon commented Nov 22, 2018

(As a workaround, the current ISO should have unsquashfs installed, so you should be able to use that to extract the files you're looking for instead of using mount.)

@tianon
Copy link
Contributor

@tianon tianon commented Nov 22, 2018

In fact, you can probably just do something like tce-load -wicl tzdata and get them installed into /usr/share/zoneinfo too.

@tianon
Copy link
Contributor

@tianon tianon commented Nov 22, 2018

In fact, I'm going to close this issue now since I'd say tce-load or stealing files via a container is the way to do this if you need something other than UTC on the host for some reason -- if your container needs a particular timezone, I think you're better off setting up /etc/localtime appropriately there instead.

(But I'm still going to add CONFIG_SQUASHFS back.)

@tianon
Copy link
Contributor

@tianon tianon commented Nov 22, 2018

#1359 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
You can’t perform that action at this time.