Unable to create directory. Permission denied inside docker container
Unable to create folder during image creation with root user added to sudoers group. Here is my Dockerfile:
FROM ubuntu:16.04
RUN apt-get update && \
apt-get -y install sudo
RUN adduser --disabled-password --gecos '' newuser \
&& adduser newuser sudo \
&& echo '%sudo ALL=(ALL:ALL) ALL' >> /etc/sudoers
USER newuser
RUN mkdir -p /newfolder
WORKDIR /newfolder
I get an error: mkdir: cannot create directory '/newfolder': Permission denied
source to share
Filesystems inside a Docker container work the same way as files outside a Docker container: you need appropriate permissions if you are going to create files or directories. In this case, you are trying to create /newfolder
as a non-root user (since the directive USER
changes the UID used to run any subsequent commands). It won't work because it /
belongs root
and has a regime dr-xr-xr-x
.
Try this instead:
RUN mkdir -p /newfolder
RUN chown newuser /newfolder
USER newuser
WORKDIR /newfolder
This will create a directory like root
and then chown
it.
source to share