Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied inside Docker container

Tags:

docker

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 :)

like image 649
Héctor Avatar asked Jan 20 '16 14:01

Héctor


People also ask

How do I fix permission denied Docker?

If running elevated Docker commands does not fix the permission denied error, verify that your Docker Engine is running. Similar to running a docker command without the sudo command, a stopped Docker Engine triggers the permission denied error. How do you fix the error? By restarting your Docker engine.

How do I fix Docker got permission denied while trying to connect to the Docker daemon socket?

Fix 1: Run all the docker commands with sudo If you have sudo access on your system, you may run each docker command with sudo and you won't see this 'Got permission denied while trying to connect to the Docker daemon socket' anymore.

How do I run a Docker container as a root user?

Docker containers are designed to be accessed as root users to execute commands that non-root users can't execute. We can run a command in a running container using the docker exec. We'll use the -i and -t option of the docker exec command to get the interactive shell with TTY terminal access.


1 Answers

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.

like image 168
Héctor Avatar answered Sep 20 '22 14:09

Héctor