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

timezone setting on MacOS broken again #61

Closed
lsf37 opened this issue Nov 21, 2022 · 8 comments
Closed

timezone setting on MacOS broken again #61

lsf37 opened this issue Nov 21, 2022 · 8 comments
Assignees

Comments

@lsf37
Copy link
Member

lsf37 commented Nov 21, 2022

It looks like a new form of #16 has reappeared. For

make user

I'm getting

docker run \
	-it \
	--hostname in-container \
	--rm \
	-u 501:20  --group-add stack \
	--group-add sudo \
	-v /Users/kleing/src/seL4/sel4-camkes-l4v-dockerfiles:/host:z \
	-v kleing-home:/home/kleing \
	-v /usr/share/zoneinfo.default/Australia/Sydney:/etc/localtime:ro \
	user_img-kleing bash
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/usr/share/zoneinfo.default/Australia/Sydney" to rootfs at "/etc/localtime": mount /usr/share/zoneinfo.default/Australia/Sydney:/etc/localtime (via /proc/self/fd/14), flags: 0x5001: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
make: *** [Makefile:131: user_run] Error 125

If I delete the time zone line and inspect the container, there is indeed already a symlink in /etc/localtime:

kleing@in-container:/host$ ls -l /etc/localtime 
lrwxrwxrwx 1 root root 27 Aug 16  2021 /etc/localtime -> /usr/share/zoneinfo/Etc/UTC

This is on MacOS Ventura (13.0.1) and Docker version 20.10.21, build baeda1f

@lsf37
Copy link
Member Author

lsf37 commented Nov 21, 2022

It does appear that passing the time zone via TZ as an environment variable is more stable than trying to link the time zone file directly.

The main question is how to reliably get the time zone string from the host OS. On reasonably recent Debian, Ubuntu, and MacOS at least, the /etc/localtime link seems to always exist, so we could try to extract it from that.

Ubuntu and Debian both seem to support reading /etc/timezone which for me both report the correct string Australia/Sydney. I think Debian also sets TZ. So we could do the following in decreasing priority

  • check TZ env, if set use that
  • check /etc/timezone, if the file exists use its contents
  • check for MacOS, if yes, strip /var/db/timezone/zoneinfo/ from the link in /etc/localtime
  • otherwise print a warning that time zone is not set

@lsf37
Copy link
Member Author

lsf37 commented Nov 21, 2022

We could also delete the symlink in the container, of course. Not sure if that throws anything into disarray.

@wom-bat
Copy link
Member

wom-bat commented Nov 24, 2022

Just use TZ. It's meant to be there (POSIX standard). /etc/localtime is a GNU extension that makes things faster if it's there.

@lsf37
Copy link
Member Author

lsf37 commented Nov 24, 2022

TZ is unfortunately not set on most platforms I tried (in fact, it was set only on Debian). It works when I set it in the container, but my main problem is trying to get the correct time zone string from the host.

@LukeMondy
Copy link
Contributor

Yes, adding MacOS support was a real spanner in the works, unfortunately :(

What does the /usr/share/zoneinfo.default/Australia/Sydney file (or folder) look like on the host?

Otherwise, your bullet point list of options sounds fair enough.

@lsf37
Copy link
Member Author

lsf37 commented Nov 25, 2022

For the timezone file itself I get the following on MacOS:

ls -l /usr/share/zoneinfo.default/Australia/Sydney 
-rw-r--r--  4 root  wheel  2195 28 Oct 19:43 /usr/share/zoneinfo.default/Australia/Sydney

Before I try all that extraction stuff, I'll give it the old method another shot by deleting the symbolic link in the docker container so that there is no conflict when docker is trying to mount there. Peter mentioned that if the file/link does not exist it's just going to default to UTC which is what it's already doing anyway, so there should be no additional adverse effects if the mount command doesn't work for some reason.

@lsf37 lsf37 self-assigned this Jan 10, 2023
@Willmish
Copy link

Hi all, also run into the wall of getting the docker image up and running on an M1 Mac, I've set the environment var export DOCKER_BUILDKIT=0 (ran into the same issue as #40 , when pulling extras image), but I believe I have arrived at the same issue as this one describes:

When running make user, fails at:

docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/usr/share/zoneinfo.default/Europe/London" to rootfs at "/etc/localtime": mount /usr/share/zoneinfo.default/Europe/London:/etc/localtime (via /proc/self/fd/9), flags: 0x5001: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
make: *** [Makefile:131: user_run] Error 125```

@lsf37
Copy link
Member Author

lsf37 commented May 20, 2024

For the timezone file itself I get the following on MacOS:

ls -l /usr/share/zoneinfo.default/Australia/Sydney 
-rw-r--r--  4 root  wheel  2195 28 Oct 19:43 /usr/share/zoneinfo.default/Australia/Sydney

Before I try all that extraction stuff, I'll give it the old method another shot by deleting the symbolic link in the docker container so that there is no conflict when docker is trying to mount there. Peter mentioned that if the file/link does not exist it's just going to default to UTC which is what it's already doing anyway, so there should be no additional adverse effects if the mount command doesn't work for some reason.

This actually seems to have worked fine, so I’m closing this issue for now.

@lsf37 lsf37 closed this as completed May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants