I'm trying to create a docker image with docker-compose for my web application. My web application needs permissions to write files on file system.
My Dockerfile contains
# some other stuff
RUN addgroup -S web && adduser -S -g web web
USER web
I want to mount my current .
directory to /code
in docker container;
When I perform docker-compose build
&& docker-compose up
, It occurs that my /code
directory in container is owned for user "1000:1000", not my user that I created in Dockerfile.
version: '2'
services:
admin:
build:
context: .
dockerfile: Dockerfile
command: python manage.py 0.0.0.0 8030
volumes:
- .:/code
ports:
- 9000:8030
stdin_open: true
tty: true
volumes:
.:
driver_opts:
o: uid=100,gid=65533
As you see, I tried to pass driver_opts with my user uid and gid parameters; but it didn't help.
My question is: what should I do to mount my directory .
to /code
in docker container privileges for user web
?
OS: Ubuntu 16.04
docker version 17.09.0-ce
docker-compose version 1.8.0
We can also create a volume with Docker compose service or also specify existing volumes. For example, the following screenshot shows a 'docker-compose' file that creates a docker-compose service with a volume. As a result of the above command, a volume with the name 'myvolume' gets created.
to be able to read and write to and from /var/run/docker. sock , you must either be root or being in the docker group. docker-compose is another cli it has the same requirements as docker .
Multiple containers can mount the same volume. Running docker-compose up will create a volume named <project_name>_html_files if it doesn't already exist .
You can try with:
RUN addgroup -g 1000 web && \
adduser -G web -g web -s /bin/sh -D web
your user will be able to write to the mounted directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With