P
P
Pandemonium2020-05-26 17:36:33
Debian
Pandemonium, 2020-05-26 17:36:33

How to make Docker work non-root?

I work on the server not as a root user, the user is added to the Docker group. As a user, I can create and run containers without sudo. But when forwarding directories from docker, the directories are created with the owner root and because of this, working in them is difficult. How to make folder owner be user?

More:

docker run -d \
    -p 80:80 \
    --name nginx \
    --restart always \
    -v /home/server/nginx/html:/usr/share/nginx/html \
    -v /home/server/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \
    nginx


For example, when starting a container with Nginx, a server, server/nginx and server/nginx/html directory is created in the home directory, and at the same time, all three directories belong to the root user - because of this, I cannot put any necessary files into them via FTP , the option to manually change the owner of all directories each time is not suitable. How can I make sure that they are created with the owner user, not root?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2020-05-26
@deepblack

For example like this:

FROM ubuntu:xenial
RUN useradd -d /home/ubuntu -ms /bin/bash -g root -G sudo -p ubuntu ubuntu
RUN mkdir /opt/myvolume  && chown ubuntu /opt/myvolume
WORKDIR /home/ubuntu
VOLUME /opt/myvolume

More can be seen here:
  • Change owner of files created inside a Docker container
  • Understanding user file ownership in docker: how t...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question