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

After Docker upgrade - results in "The path /etc/localtime is not shared from OS X and is not known to Docker" #2396

Open
shusak opened this Issue Jan 10, 2018 · 65 comments

Comments

Projects
None yet
@shusak
Copy link

shusak commented Jan 10, 2018

Expected behavior

Docker upgrade shouldn't affect already working mount mappings.

Actual behavior

Upgrade to new version of docker on Mac OSX now results in "The path /etc/localtime
is not shared from OS X and is not known to Docker".

Information

  • Full output of the diagnostics from "Diagnose & Feedback" in the menu

Docker for Mac: version: 17.12.0-ce-mac46 (a61e84b8bca06b1ae6ce058cdd7beab1520ad622)
macOS: version 10.12.6 (build: 16G1114)
logs: /tmp/072847D3-A6CD-4D63-BC1A-BE8199F81553/20180110-104443.tar.gz
[OK] db.git
[OK] vmnetd
[OK] dns
[OK] driver.amd64-linux
[OK] virtualization VT-X
[OK] app
[OK] moby
[OK] system
[OK] moby-syslog
[OK] kubernetes
[OK] env
[OK] virtualization kern.hv_support
[OK] slirp
[OK] osxfs
[OK] moby-console
[OK] logs
[OK] docker-cli
[OK] menubar
[OK] disk

  • A reproducible case if this is a bug, Dockerfiles FTW
  • Page URL if this is a docs issue or the name of a man page

Steps to reproduce the behavior

1.On previous version, Existing docker run command executed successfully as:

docker run -d -p 80 \
    --name ${CONTAINER_NAME} \
    --restart=always \
    -v /etc/localtime:/etc/localtime:ro \
    -v ${ENV_APPDIR}/app:/usr/share/app:ro \
    -l agent-host=${agent_host} \
    ${CONTAINER_NAME}
  1. Upgrade to new Docker release
  2. Same docker run command now fails with
docker: Error response from daemon: Mounts denied:
The path /etc/localtime
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.

@shusak shusak changed the title Docker upgrade now results in "The path /etc/localtime is not shared from OS X and is not known to Docker" After Docker upgrade - results in "The path /etc/localtime is not shared from OS X and is not known to Docker" Jan 10, 2018

@gpirescampos

This comment has been minimized.

Copy link

gpirescampos commented Jan 11, 2018

Having the same problem

@drupler

This comment has been minimized.

Copy link

drupler commented Jan 12, 2018

I am also having same problem

@konstantinzolotarev

This comment has been minimized.

Copy link

konstantinzolotarev commented Jan 12, 2018

Same on me

@kumvem

This comment has been minimized.

Copy link

kumvem commented Jan 12, 2018

Facing same issue. Downgraded docker to Version 17.09.1-ce-mac42 to proceed for now.

@netcookies

This comment has been minimized.

Copy link

netcookies commented Jan 14, 2018

Same on me

@Casper-O

This comment has been minimized.

Copy link

Casper-O commented Jan 14, 2018

I also have the same issue. Downgrading if i can figure out how

@justincormack

This comment has been minimized.

Copy link
Member

justincormack commented Jan 14, 2018

If you go to Preferences/File Sharing, is /etc in the list, and does adding it again fix the issue?

@konstantinzolotarev

This comment has been minimized.

Copy link

konstantinzolotarev commented Jan 14, 2018

@justincormack No /etc is not in the list and it's not possible to add it there with message:

The path /etc is reserved by Docker however it may be possible to export specific subdirectories.
@purinda

This comment has been minimized.

Copy link

purinda commented Jan 14, 2018

Having the same issue,

@justincormack

This comment has been minimized.

Copy link
Member

justincormack commented Jan 15, 2018

Ah ok, it looks like the host does not have an /etc/localtime file. If it did, it would only have UTC in, you are probably better off adding that to your container or omitting it.

What exactly are you trying to achieve by bind mounting it? Which local time are you interested in?

@shusak

This comment has been minimized.

Copy link
Author

shusak commented Jan 16, 2018

On my machine:

$ ls -la /etc/localtime
lrwxr-xr-x  1 root  wheel  36 Aug 24 13:17 /etc/localtime -> /usr/share/zoneinfo/America/New_York

I think this technique is a popular solution to configure a container's timezone.

@Gengar003

This comment has been minimized.

Copy link

Gengar003 commented Jan 16, 2018

I have this same issue, with

  • Version 17.12.0-ce-mac47 (21805)
  • Version 17.12.0-ce-mac46 (didn't record build#)

Specifically on OSX, /etc is actually a symlink to /private/etc.

I know that /etc cannot be added as a shared directory. Presumably, because it'll be overlaid on the Moby VM at /etc which will kill the actual VM that serves our Docker daemon (this was always my understanding).

By happy coincidence, though, that /private/etc symlink would be resolved by the Docker-for-Mac system and since /private is a shared directory, it would work.

Could this be a regression in docker / Docker-for-Mac's handling of symlinks in bind-mounts?

For now, I work around the issue by re-installing an older version: Docker-for-Mac 17.09.1-ce-mac42 (21090)

@richtong

This comment has been minimized.

Copy link

richtong commented Jan 16, 2018

If you do add /etc/localtime to the Docker for Mac Preferences/File Sharing, then you get a different error which seems to show that on Version 17.12.0-ce-mac45 it is actually trying to mkdir the directory on the MacOS side. As an aside this works perfectly in Ubuntu 16.04 with the latest docker, so it looks like a regression:

docker run -it -v /etc/localtime:/etc/localtime:ro hello-world
docker: Error response from daemon: error while creating mount source path '/etc/localtime': mkdir /etc/localtime: file exists.
@gi-el

This comment has been minimized.

Copy link

gi-el commented Jan 17, 2018

Same issue: here's my OSX-specific workaround.

  • Make sure you have the tzdata package installed in the container
  • Add -e TZ=`ls -la /etc/localtime | cut -d/ -f8-9` to the docker run command line
@richtong

This comment has been minimized.

Copy link

richtong commented Jan 17, 2018

@fedorov

This comment has been minimized.

Copy link

fedorov commented Feb 20, 2018

I have the same issue, and I need to make it work with docker-compose. Any suggestions?

@fedorov

This comment has been minimized.

Copy link

fedorov commented Feb 20, 2018

Solved ... specified TZ in the .env file for docker-compose. Not sure if it works, but at least I could start it up ...

@ikhere

This comment has been minimized.

Copy link

ikhere commented Feb 24, 2018

Tried setting TZ in .env file and still docker-compose fails to start.

$ echo "TZ=$(ls -la /etc/localtime | cut -d/ -f8-9)" >> .env
$ docker-compose up -d
...
Starting blockbox_cinder-volume_1 ... error

ERROR: for blockbox_cinder-volume_1  Cannot start service cinder-volume: Mounts denied:
The path /etc/localtime
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.
.
@OnkelTem

This comment has been minimized.

Copy link

OnkelTem commented Feb 28, 2018

We are also affected by this change. Please fix it.

@peckhouse

This comment has been minimized.

Copy link

peckhouse commented Mar 2, 2018

Any update on this bug?
Will we have a fix soon?

@sprive

This comment has been minimized.

Copy link

sprive commented Mar 2, 2018

Hey all - this worked for me, on High Sierra:

$ mkdir ~/etc
$ vi ~/etc/timezone
$ cat ~/etc/timezone
America/New_York

Then my docker-compose.yml mount looks like:

$ grep -C2 timezone docker-compose.yml 
      volumes:
        - /Users/sprive/home-assistant/localdata:/config
        - ~/etc/timezone:/etc/localtime:ro
      restart: always
      network_mode: host

Some thoughts:

  • I don't know (and don't care) why it doesn't work anymore on OSX. If you never change timezones the above is OK. If NOT...
    • There are other ways (like .env) to get TZ string into your container, if you don't like this way. You do not have to be blocked by this.
    • NOTE: if trying another way, try to keep it at the mount or ENV level (so it's runtime... rather than embed it into the image, which would work - but isn't a a good technique.. )
@t0sche

This comment has been minimized.

Copy link

t0sche commented Mar 7, 2018

@sprive this worked for me. Thanks!

@lacvapps

This comment has been minimized.

Copy link

lacvapps commented Mar 20, 2018

Commenting to say this is still an issue on High Sierra, latest Docker for mac

@harshashinde

This comment has been minimized.

Copy link

harshashinde commented Mar 26, 2018

+1

@docker-desktop-robot

This comment has been minimized.

Copy link
Collaborator

docker-desktop-robot commented Sep 12, 2018

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale comment.
Stale issues will be closed after an additional 30d of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle stale

@shusak

This comment has been minimized.

Copy link
Author

shusak commented Sep 12, 2018

/remove-lifecycle stale
/lifecycle frozen

I don't feel we have the resolution (or official answer for this).

@lovemyliwu

This comment has been minimized.

Copy link

lovemyliwu commented Sep 21, 2018

also face to it Version 18.06.1-ce-mac73 (26764)

@mrdulin

This comment has been minimized.

Copy link

mrdulin commented Sep 28, 2018

same issue

@asmaloney

This comment has been minimized.

Copy link

asmaloney commented Oct 9, 2018

Just ran into this too.

Is there another (better) way to keep clocks in sync? Seems an obvious thing to want to do...

@kamaral75

This comment has been minimized.

Copy link

kamaral75 commented Nov 20, 2018

I went to Preferences > File Sharing and added the path /etc/localtime then clicked Apply & Restart. That seemed to alleviate the issue in my case.

@tucknology

This comment has been minimized.

Copy link

tucknology commented Dec 2, 2018

I'm having the same problem as OP.

This didn't work:

I went to Preferences > File Sharing and added the path /etc/localtime then clicked Apply & Restart. That seemed to alleviate the issue in my case.

@smlng

This comment has been minimized.

Copy link

smlng commented Dec 6, 2018

I got it working by resolving /etc/localtime to its true location by using realpath, i.e.:

export ETC_LOCALTIME=$(realpath /etc/localtime)
echo ${ETC_LOCALTIME}
/private/var/db/timezone/tz/2018g.1.0/zoneinfo/Europe/Berlin
docker run -it --rm -v "${ETC_LOCALTIME}:/etc/localtime:ro" alpine date
Thu Dec  6 16:09:40 CET 2018

compared to

docker run -it --rm alpine date
Thu Dec  6 15:10:13 UTC 2018
@smlng

This comment has been minimized.

Copy link

smlng commented Dec 7, 2018

as realpath is not available by default on macOS (I installed it via brew) you need to use readlink instead: export ETC_LOCALTIME=$(readlink /etc/localtime)

@rajsahae

This comment has been minimized.

Copy link

rajsahae commented Dec 10, 2018

FYI I'm on 18.09.0 and this is still an issue.
I'm using the workaround to use realpath on /etc/localtime then mounting that path.

Since this looks like a fix was merged just 4 days ago, I'm looking forward to testing the fix asap. Thanks.

@smlng

This comment has been minimized.

Copy link

smlng commented Dec 10, 2018

I'd say this is actually no problem with docker, but rather (kind of) a security feature of macOS to protect special directory such as /etc where configurations are stored. However, the /etc/localtime maps to a file that is not in a not-protected directory, hence resolving it to its true location makes it mountable by docker on macOS.

Btw. the merge you see above is a PR I made for https://github.com/RIOT-OS/RIOT - so sadly no fix for docker on macOS.

@charlietomo

This comment has been minimized.

Copy link

charlietomo commented Dec 12, 2018

I'm also having this issue and have tried the options in this thread but not having any luck. Surely there should be a way that does not involve installing a bunch of other things e.g. realpath.

Can't the docker image use NTP in order to get the time?

@smlng

This comment has been minimized.

Copy link

smlng commented Dec 12, 2018

NTP does not solve the timezone issue which is addressed with /etc/localtime - also note that the latter mount does not sync the clock, that is actually done by docker automatically, i.e. the clock matches the host clock but you still need the timezone information. TL;DR: NTP does not solve the issue mentioned here and also NTP is not needed, as long as the docker host system clock is in sync.

@smlng

This comment has been minimized.

Copy link

smlng commented Dec 12, 2018

also note: you don't need the realpath just use readlink (which is available on macOS by default, nothing to install) as mentioned in
#2396 (comment)

@charlietomo

This comment has been minimized.

Copy link

charlietomo commented Dec 19, 2018

Thanks @smlng but I'm a bit of a learner here. How would I use readlink?

I have two lines related to time in my docker-compose.yml:

      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
@smlng

This comment has been minimized.

Copy link

smlng commented Dec 19, 2018

as you cannot use shell command directly in the docker-compose.yml you have to use environment variables. Btw. I don't have /etc/timezone file/link on my macOS.

First edit the .yml file and change as follows:

- ${ETC_LOCALTIME}:/etc/localtime:ro

Second, in a shell fill the env variable and store in .env file, which is automatically used by docker-compose if present.

cd <path/to/yml>
echo "ETC_LOCALTIME=$(readlink /etc/localtime)" >> .env

Finally, run docker-compose as usual in the directory where the .env and .yml file are (check with ls -la).

Also note: I needed to add /var/db to the shared folders in the Docker client for macOS.

@charlietomo

This comment has been minimized.

Copy link

charlietomo commented Dec 21, 2018

Thanks @smlng that helped me get rid of those errors. I just commented out - /etc/timezone:/etc/timezone:ro as I understand macOS doesn't have it (as you mentioned).

@lc4t

This comment has been minimized.

Copy link

lc4t commented Jan 8, 2019

MacOS 10.13.6
Docker version 18.06.0-ce, build 0ffa825

I follow @smlng 's answer, create .env and modify .yml, AND add my timezone /var/db/timezone/zoneinfo/Asia/ to Share path.

Then it works

@smlng

This comment has been minimized.

Copy link

smlng commented Jan 8, 2019

@lc4t thanks for confirming.

In general I would suggest to add a not so specific shared path, bc then you're bound to that single timezone. I'd rather use /var/db or /var/db/timezone ... at least if you want to share your docker files (or what ever setup) with a larger (world wide) community.

Anyway, good to know it works!

@Nottt

This comment has been minimized.

Copy link

Nottt commented Apr 4, 2019

So this is why my docker users had issue with this. I'd prefer if docker and OS X could just keep /etc/localtime to be cross-platform friendly.

But if you can contact the docker owner, all he needs to do is add something like this to the dockerfile to support other platforms

RUN apt-get update && apt install -y tzdata and then start the container with a variable like -e TZ=America/New_York

If you can't fix this at source, just clone the docker repo in your machine, edit the Dockerfile locally, then build the docker again with that Dockerfile and run it with that variable.

Should work for people that don't have /etc/localtime. But I'd just use linux :P

@lizilong007

This comment has been minimized.

Copy link

lizilong007 commented Apr 10, 2019

@Gengar003 Thank you.

The best way is to use the lower version...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.