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

ZINC_DATA_PATH is not writable #512

Closed
jwillmer opened this issue Sep 6, 2022 · 8 comments · Fixed by #516
Closed

ZINC_DATA_PATH is not writable #512

jwillmer opened this issue Sep 6, 2022 · 8 comments · Fixed by #516

Comments

@jwillmer
Copy link

jwillmer commented Sep 6, 2022

What were you trying to achieve?
Running the docker image

What action did you take?
Running stock example with mapped valume path returns error. Same is true if I don't specify any volume mount.

docker run -v /root/docker/zincsearch:/data -e DATA_PATH="/data" -p 4080:4080 \
    -e ZINC_FIRST_ADMIN_USER=admin -e ZINC_FIRST_ADMIN_PASSWORD=Complexpass#123 \
    --name zinc public.ecr.aws/h9e2j3o7/zinc:latest

What action/response/output did you expect?
Running app

What actually happened?

{"level":"debug","time":"2022-09-06T14:44:50Z","message":"open .env: no such file or directory"}
{"level":"fatal","error":"mkdir data/_test_: permission denied","time":"2022-09-06T14:44:50Z","message":"ZINC_DATA_PATH is not writable"}

How to reproduce the issue?
Just start it

What version of ZincSearch are you using?
I tried with latest and 0.3.1

Anything else that you can tell that will help us diagnose and resolve the issue efficiently?
I am running a ubuntu server.

@prabhatsharma
Copy link
Collaborator

can you try:

chmod a+rwx /root/docker/zincsearch

@tymonx
Copy link
Contributor

tymonx commented Sep 6, 2022

This is caused by wrong user:group between the directory from the host machine /root/docker/zincsearch that assume is root:root and from container that is appuser:appuser set in the Zinc Dockerfile with disabled write permission for others when creating new directory using the mkdir command from the host machine.

To solve this, overwrite the Zinc image user with the --user root Docker run argument:

docker run --user root -v /root/docker/zincsearch:/data -e DATA_PATH="/data" -p 4080:4080 \
    -e ZINC_FIRST_ADMIN_USER=admin -e ZINC_FIRST_ADMIN_PASSWORD=Complexpass#123 \
    --name zinc public.ecr.aws/h9e2j3o7/zinc:latest

If you are also planning using Zinc in Docker Compose or Docker Swarm use the user: root directive. It also work for named volumes. For volumes with host path as source --volume <host-path>:<container-path> in OS with SELinux add :rw,z at the end of the volume option --volume <host-path>:<container-path>:rw,z.

@jwillmer
Copy link
Author

jwillmer commented Sep 7, 2022

Ok, great, thank you for the workaround. But I think you should fix this. You can't use a user without root and then break the deployment / require workarounds for it. I uploaded a gist on how we prevent this from happening in our images. Please have a look and see if it is any use for you: Create image without root user and folder access

@tymonx
Copy link
Contributor

tymonx commented Sep 7, 2022

I agree with @jwillmer (sorry but I'm not a Zinc contributor only humble Zinc user).

Zinc team should create and add default directory with ownership for appuser:appuser and set the DATA_PATH environment variable on default to this value in their Dockerfile. This should work with host source and also named volumes out-of-box.

@hengfeiyang
Copy link
Contributor

@jwillmer i saw the link, if you don't mount directory it can work. But if you mount outside directory, in container we are nothing can do except use root user for zinc.

You can run zinc without mount directory, it no need create directory and give it permission:

docker run  -p 4080:4080 -e ZINC_FIRST_ADMIN_USER=admin -e ZINC_FIRST_ADMIN_PASSWORD=Complexpass#123  --name zinc public.ecr.aws/zinclabs/zinc:latest

@jwillmer
Copy link
Author

jwillmer commented Sep 7, 2022

As I said event this does not work
image

@hengfeiyang
Copy link
Contributor

@jwillmer, Thanks, i will fix it.

tymonx added a commit to tymonx/zinc that referenced this issue Sep 7, 2022
It fixes zincsearch#512

Changed user and group to zinc:zinc to match general convention used in
other services like rabbitmq, mysql, etc..

Added default ZINC_DATA_PATH=/var/lib/zinc. It follows Linux filesystem
hierarchy convention:

https://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/var.html
@tymonx
Copy link
Contributor

tymonx commented Sep 7, 2022

@hengfeiyang I have created a proper Pull Request that will fix this #516

docker volume create zinc

docker run -v zinc:/var/lib/zinc -p 4080:4080 \
    -e ZINC_FIRST_ADMIN_USER=admin -e ZINC_FIRST_ADMIN_PASSWORD=Complexpass#123 \
    --name zinc zinc

I can also create Pull Request for Zinc documentation to encourage people to use named volumes rather that host source paths.

If someone really want to use host source path (I discourage it):

mkdir -p zinc
chmod a+w zinc

docker run -v "$(pwd)/zinc:/var/lib/zinc" -p 4080:4080 \
    -e ZINC_FIRST_ADMIN_USER=admin -e ZINC_FIRST_ADMIN_PASSWORD=Complexpass#123 \
    --name zinc zinc

I would not recommended to add 0777 permissions in the Dockerfile. It will only unnecessary expose Zinc data.

hengfeiyang pushed a commit that referenced this issue Sep 8, 2022
* Add persistent location with proper permissions

It fixes #512

Changed user and group to zinc:zinc to match general convention used in
other services like rabbitmq, mysql, etc..

Added default ZINC_DATA_PATH=/var/lib/zinc. It follows Linux filesystem
hierarchy convention:

https://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/var.html

* Change default Zinc data to /data

* Add persistent directory in other Dockerfiles
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

Successfully merging a pull request may close this issue.

4 participants