Answer the question
In order to leave comments, you need to log in
How to give root access to all files in docker?
When running containers, docker creates a read-only src folder (project folder), how can I set root permissions for this folder?
docker-compose.yml
version: '3'
services:
database:
build:
context: ./containers/database
environment:
- MYSQL_DATABASE=${DATABASE_NAME}
- MYSQL_USER=${DATABASE_USER}
- MYSQL_PASSWORD=${DATABASE_PASSWORD}
- MYSQL_ROOT_PASSWORD=${DATABASE_ROOT_PASSWORD}
ports:
- "33063:3306"
volumes:
- ./containers/database/init.sql:/docker-entrypoint-initdb.d/init.sql
- ./containers/database/data:/var/lib/mysql
php-fpm:
build:
context: ./containers/php-fpm
depends_on:
- database
environment:
- APP_ENV=${APP_ENV}
- APP_SECRET=${APP_SECRET}
- DATABASE_URL=mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@database:3306/${DATABASE_NAME}?serverVersion=5.7
volumes:
- ./src:/var/www
nginx:
build:
context: ./containers/nginx
volumes:
- ./src:/var/www
- ./containers/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./containers/nginx/sites/:/etc/nginx/sites-available
- ./containers/nginx/conf.d/:/etc/nginx/conf.d
- ./containers/logs:/var/log
depends_on:
- php-fpm
ports:
- "8020:80"
FROM nginx:alpine
WORKDIR /var/www
CMD ["nginx"]
EXPOSE 80
FROM mariadb:latest
CMD ["mysqld"]
EXPOSE 3306
FROM php:fpm-alpine
COPY wait-for-it.sh /usr/bin/wait-for-it
RUN chmod +x /usr/bin/wait-for-it
RUN apk --update --no-cache add git
RUN docker-php-ext-install pdo_mysql
COPY --from=composer /usr/bin/composer /usr/bin/composer
WORKDIR /var/www
CMD composer install ; wait-for-it database:3306 -- bin/console doctrine:migrations:migrate ; php-fpm
RUN apk add bash
RUN wget https://get.symfony.com/cli/installer -O - | bash && \
mv /root/.symfony/bin/symfony /usr/local/bin/symfony
RUN /var/www
EXPOSE 9000
Answer the question
In order to leave comments, you need to log in
Tried to reproduce - did not work.
Docker by default starts its containers already as root and when creating a directory in the container directly from the host itself through the same Dockerfile, the directory is created with the user and group root and rights 755
The directory "./src" is not created, but forwarded to "/var/www", it's not clear why root is here and where to set the rights? In a container? On the host? I suppose that you need to edit the sources on the host while the container is running, then you need to set the user in the container with the same uid as on the host (usually 1000, see the "echo $UID" output in the console). You can set it via docker-compose.yml and of course users can be created and set in the Dockerfile
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question