Answer the question
In order to leave comments, you need to log in
How to set user for volume in docker-compose.yml?
There is docker-compose.yml:
version: '3'
services:
php:
volumes:
- "./web:/var/www/html"
Answer the question
In order to leave comments, you need to log in
This is not a volume, this is a mount and the rights to it are the same as on ./web.
Put chmod 777 locally or mount /etc/passwd /etc/shadow and customize the container so that the uid gid matches the host.
I in a similar case threw /etc/passwd and /etc/groups into the container,
after that the link uid-name group-gid works.
Max , it doesn't work. After prescribing a group and user, the server stops responding altogether. With additions according to your scheme (if, of course, I understood it correctly), it turns out like this:
version: '3'
services:
web:
image: nginx:alpine
volumes:
- "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
- "./etc/ssl:/etc/ssl"
- "./web:/var/www/html"
- "./etc/nginx/default.template.conf:/etc/nginx/conf.d/default.template"
- "/etc/passwd:/etc/passwd"
- "/etc/groups:/etc/groups"
ports:
- "80:80"
- "3000:443"
environment:
- NGINX_HOST=${NGINX_HOST}
command: /bin/sh -c "envsubst '$$NGINX_HOST' < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
restart: always
user: "1001:1001"
depends_on:
- php
- mysqldb
php:
build:
context: .
dockerfile: DockerfilePhpWithGit
restart: always
user: "1001:1001"
volumes:
- "./etc/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
- "./web:/var/www/html"
- "/etc/passwd:/etc/passwd"
- "/etc/groups:/etc/groups"
In such a situation, I modified local users in the entrypoint.sh of the container, getting the uid from the rights of the mounted directory:
SRC_DIR=/path/to/mounted/volume
DIR=/path/to/dir
USER=www-data
GROU=www-data
$uid=$(stat -c '%u' $SRC_DIR)
$gid=$(stat -c '%g' $SRC_DIR)
echo $uid > /root/uid
echo $gid > /root/gid
usermod -u $uid $USER
groupmod -g $gid $GROUP
mkdir -p $DIR
chown -R $USER:$GROUP $DIR
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question