How to save data as a non-root user in a container? - docker

I try to use docker in the cluster of my school.And I have add my accout into docker group.I run the container by:docker run -it -v ~/documents:/home/fenics/shared fenicsdrl1 /bin/bash.But I was told that I don't have the permissions when I tried to write my data into a file.Here are my error message:
tensorflow.python.framework.errors_impl.PermissionDeniedError: log/tensorboard/_model=PPO2_default_Mlp1_step_1_episode_18CPU_time=2022-10-27_06_56_28_1; Permission denied
I tried to run this container by:docker run -it -v ~/documents:/home/fenics/shared fenicsdrl1 /bin/bash --privileged=true and docker run -it --user==$UID:$(id -g $USER) -v ~/documents:/home/fenics/shared fenicsdrl1 /bin/bash.But it didn't work.
Any advises would be appreciated:).

I think you don't have write permission in ~/documents folder, you need create new folder with full permission and replace ~/documents by that new folder.

Have you tried using the sudo command?

Related

Getting "docker: open .env: permission denied." when trying to pass a .env file to docker run

I have no problems running the test "Hello World" image.
But when I try to pass the --env-file variable as part of my docker run command I am getting docker: open .env: permission denied.
I have tried granting full permissions on my .env file but not joy still.
The command I am running is docker run --network host --env-file .env <IMAGE_ID>
Any help appreciated
Step 1: Add the current user to the docker group by executing the below command
sudo usermod -aG docker $USER
Step 2: Change the permissions of docker socket which can able to connect to the docker daemon
sudo chmod 666 /var/run/docker.sock
A clean reinstall of docker fixed the problem

Chmod permission issue when running a docker container

I'm trying to run a simple-ca container (https://github.com/jcmoraisjr/simple-ca) in docker (running in a fresh install of ubuntu 18.04.4) but every time I run the docker command
docker run --name simple-ca -p 80:8080 -p 443:8443 -e CERT_TLS_DNS=ca.mycompany.com -e CA_CN=MyCompany-CA -v /var/lib/simple-ca/ssl:/ssl quay.io/jcmoraisjr/simple-ca:latest
I get the error
chmod: private: Operation not permitted
I have already granted systemd-network ownership of the folder /var/lib/simple-ca/ and ran the command
/bin/bash -c 'chown $(docker run --rm quay.io/jcmoraisjr/simple-ca id -u lighttpd) /var/lib/simple-ca/ssl'
to grant lighthttpd rights on the SSL folder
Anyone have any idea on what may have went wrong?
It was a permission issue that caused the container to fail to start. I had to remove the folder /var/lib/simple-ca and let the systemd startup re-create it with Lighttpd user id.
Once that was done, I used the container console access to directly edit the CA config files and the whole simple-ca was working as expected.

docker all files belong to root

I recently started using docker on Ubuntu 16.04.
The problem I encounter is that everytime I run any script inside docker, all new files (which docker creates) have the root:root permissions.
I have read that this is a common issue, but I cannot find a proper solution for this problem (ideally the files created by docker would have my 'local machine' user's permissions.
Is there any way to achieve this? Or should I run chown / chmod after each docker creates new files?
Just use the --user flag. If you know your UID and UID you can use it directly:
docker run --user 1000:1001 image
Or you can let your shell to evaluate it:
docker run --user $(id -u):$(id -g) image

Docker mount host volume Windows

I'm using Windows 10 and Docker version 18.03.1-ce, build 9ee9f40.
I'm trying to do docker run -it --volume="./Users:/app" ubuntu:16.04 or docker run -it -v Users:/app ubuntu:16.04 but it's not working, my directory in Docker still empty.
I have read this post and it doesn't help.
UPD: Solved.
Important step was to go to Docker Settings > Shared Drives and uncheck and check your shared drive again.
Then you can mount your volume like this:
docker run -v /host_mnt/c/Users/User/Path:/docker/path image
This command should fix it .
docker run -it -v ${PWD}:/app ubuntu:16.04
Not sure what error you got, so I am assuming
your host directory may not be correct.(solution is based on this)
Permission issue.
Please check the permissions of your folders and user permission

Permission denied inside Docker container

I have a started container gigantic_booth and I want to create the directory /etc/test:
# docker exec -it gigantic_booth /bin/bash
$ mkdir /etc/test
$ mkdir: cannot create directory '/etc/test': Permission denied
And sudo command is not found. I don't want to create this directory in image-build-time but once is started.
How can I do?
Thanks :)
I'm using jenkins image and I have just read that it has root access disabled for security reasons. https://github.com/jenkinsci/docker#installing-more-tools
I have re-built the image with this Dockerfile:
FROM jenkins
USER root
and now it works properly, it is not so secure, though.
Or just use docker exec -u thejenkinsuser.

Resources