Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Delete file created via Docker

I used a docker image to run a program on our school's server using this command.

 docker run -t -i -v /target/new_directory 990210oliver/mycc.docker:v1 /bin/bash

After I ran it it created a firectory on my account called new_directory. Now I don't have permissions to delete or modify the files.

How do I remove this directory?

like image 217
Katie Avatar asked Feb 23 '17 18:02

Katie


2 Answers

I also had this problem.

After:

docker run --name jenkins -p 8080:8080 -v $HOME/jenkins:/var/jenkins_home jenkins jenkins

I couldn't remove files in $HOME/jenkins.

Ricardo Branco's answer didn't work for me because chown gave me:

chown: changing ownership of '/var/jenkins_home': Operation not permitted

Solution:

exec /bin/bash into container as a root user:

docker exec -it --privileged --user root container_id /bin/bash

then:

cd /var/jenkins_home/ && rm -r * .*
like image 86
siulkilulki Avatar answered Sep 24 '22 17:09

siulkilulki


I made @siulkilulki's answer into one line:

docker exec --privileged --user root <CONTAINER_ID> chown -R "$(id -u):$(id -g)" <TARGET_DIR>

Note that here the CONTAINER must be up.

like image 28
pcc426 Avatar answered Sep 25 '22 17:09

pcc426