Unable to start any container when Volumes are enabled Docker Toolbox

这一生的挚爱 提交于 2019-12-22 06:47:45

问题


I am running Docker Toolbox v. 1.13.1a on Windows 7 Pro Service pack 1 x64OS. with Virtual Box Version 5.1.14 r112924

when I try to run any docker image e.g. official postgres image from Docker Hub with volumes disabled, it works fine!

But when I enable the volumes it fails.

I tried all official documentations

The VM has shared folder as required and has full access to it also shared folder screenshot

In case of my example of postgresql it crashes with following log

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... LOG:  could not link file "pg_xlog/xlogtemp.27" to "pg_xlog/000000010000000000000001": Operation not permitted
FATAL:  could not open file "pg_xlog/000000010000000000000001": No such file or directory
child process exited with exit code 1
initdb: removing contents of data directory "/var/lib/postgresql/data"

I know its the problem with folder permissions. But kinda stuck! A ton of thanks in advance


回答1:


I've been busy with this problem all day and my conclusion that it's currently simply not possible to run postgresql inside a docker container while keeping your data persistent in a separate volume.

I even tried running the container without linking to a volume and copying the data that was originally in /var/lib/postgresql into a folder of my host OS (Windows 10 Home), then copy that into the folder that got then linked to the container itself.

Alas, I got the next error:

FATAL:  data directory "/var/lib/postgresql/data/pgadmin" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.

In conclusion: There's something going wrong with the ownership and the correct user owning it and to be able to fix it, you'll need a unix commandline on Windows that is able to run docker (something currently not possible with Bash on Ubuntu on Windows that is running using Ubuntu 16.04 binaries).

Maybe, in the future, you'll be able to run the needed commands (found here, under Arbitrary --user Notes), but these are *nix commands and powershell (started by Kitematic) can't run those. Bash for Ubuntu for Windows could run those, but that shell has no connection to the docker daemon/service on windows...

TL;DR: Lost a day of work: It is currently impossible on Windows.




回答2:


I have been trying to fix this issue also ..

At first I thought it was a symlink problem (because the first error fails on " could not link .. operation not permitted)

To be sure symlink is permitted you have to :

  1. share a folder in virtualbox
  2. run virtualbox as administrator (if you account is in administrator group) Right click virtualbox.exe and select run as Administrator
  3. if your account is not administrator, add the symlink privilege with secpol.msc > "Local Policies-User Rights Assignments" add your user to "Create symbolic links"
  4. enable symlink for your shared folder in virtualbox :

VBoxManage setextradata VM_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARED_FOLDER_NAME 1

Alternatively you can also use the c:\User\username folder which is shared and symlink enabled by default dockertools installation

Now I can create symlinks in the shared folder from the docker container .. but I still have the same error "could not link ... operation not permitted"

So the reason must be somewhere else ... in the file permissions as you said but I do not see why ?



来源:https://stackoverflow.com/questions/43117938/unable-to-start-any-container-when-volumes-are-enabled-docker-toolbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!