dockerdockerfiledocker-volumedocker-containerdocker-image

Permissions in Docker volume


I am struggling with permissions on docker volume, I get access denied for writing.

This is a small part of my docker file

FROM ubuntu:18.04
RUN apt-get update && \
apt-get install -y \
apt-transport-https \
build-essential \
ca-certificates  \
curl \
vim && \............

RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && apt-get install -y nodejs

# Add non-root user
ARG USER=user01
RUN useradd -Um -d /home/$USER -s /bin/bash $USER && \
apt install -y python3-pip && \
pip3 install qrcode[pil]

#Copy that startup.sh into the scripts folder
COPY /scripts/startup.sh /scripts/startup.sh

#Making the startup.sh executable
RUN chmod -v +x /scripts/startup.sh

#Copy node API files
COPY --chown=user1 /node_api/* /home/user1/

USER $USER
WORKDIR /home/$USER

# Expose needed ports
EXPOSE 3000

VOLUME /data_storage

ENTRYPOINT [ "/scripts/startup.sh" ]

Also a small part of my startup.sh

#!/bin/bash

/usr/share/lib/provision.py --enterprise-seed $ENTERPRISE_SEED > config.json

Then my docker builds command:

sudo docker build -t mycontainer .

And the docker run command:

sudo docker run -v data_storage:/home/user01/.client -p 3008:3000 -itd mycontainer 

The problem I have is that the Python script will create the folder: /home/user01/.client and it will copy some files in there. That always worked fine. But now I want those files, which are data files, in a volume for backup porpuses. And as I am mapping with my volume I get permissions denied, so the python script is not able to write anymore.

So at the end of my dockerfile this instructions combined with the mapping in the docker run command give me the permission denied:

VOLUME /data_storage

Any suggestions on how to resolve this? some more permissions needed for the "user01"? Thanks


Solution

  • I was able to resolve my issue by removing the "volume" command from the dockerfile and just doing the mapping at the moment of executing the docker run:

    sudo docker run -v data_storage:/home/user01/.client -p 3008:3000 -itd mycontainer