I have a project like this structure:
app
- selenium
- downloads
.env
docker-compose.yml
docker-compose.yml
has 2 services: myApp
and selenium
. And this volumes set for my services:
myApp
:
volumes:
- ./app:/home/app
selenium
:
volumes:
- ./app/selenium/downloads:/home/seluser/Downloads
When I run docker compose up
in this directory, My application and selenium run up and I can develop my application. sometimes I need the selenium
container for getting some content around the web.
When selenium container
downloads a file, this file is stored in the ./app/selenium/downloads
and I can read
this file from the myApp container
.
Problem
When I changed the selenium default download directory to /home/seluser/Downloads/aaa/bbb
, this directory can access by the selenium
container with /home/app/selenium/downloads/aaa/bbb
, But I can't access aaa
directory in the myApp
container.
I can Change the permission of the aaa
directory with the root
user in the myApp
container and solve this problem, But the default download directory can be changed for every downloaded file.
What's the solution to this problem?
CodePudding user response:
I guess that you are getting troubles because your main processes of your 2 containers are running with different user. There is an easy way is to modify your Dockerfile and set the same user id (UID) for these both users. So the file/directory generated by a container can be accessed properly by the user of the other container.
An example Dockerfile
to create a user with specified UID
ARG UNAME=testuser
ARG UID=1000
ARG GID=1000
RUN groupadd -g $GID -o $UNAME
RUN useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME
There is another way using umask
to assign proper permission to file/directory generated in your selenium container (to grant READ access to all users). But I think it's more complicated and make take your time to know which umask is suitable for you https://phoenixnap.com/kb/what-is-umask