Neka
Neka

Reputation: 1664

Run nginx and php into containers with proper user for development

I have installed and configured nginx + php-fpm on their own containers. All working fine except one thing: they're running with user www-data (id: 82) and same group. So, host files, mounted to container has wrong user/group (of my primary user with 1000:1000).

How to run these containers with ability to operate with files as user 1000:1000?

Upvotes: 3

Views: 7386

Answers (2)

Neka
Neka

Reputation: 1664

User's ID can be changed in the image to map the host user's ID for that purpose.

Example for php-fpm-alpine:

RUN apk add shadow && usermod -u 1000 www-data && groupmod -g 1000 www-data

As nginx runs as root (container's root and host's root) there is no need to manipulate with UIDs

Upvotes: 14

dom
dom

Reputation: 335

for this you have to define specific user and group in container by docker-file.

Dockerfile

FROM php:7.1.6-fpm
RUN useradd -r -m -s /usr/sbin/nologin -g username -u 1000 username

ADD start-up /usr/local/bin/start-up
RUN chmod 0777 /usr/local/bin/start-up -R
ENTRYPOINT /usr/local/bin/start-up

then you have to change start-up script for php

sed -i s/'user = www-data'/'user = username'/g /usr/local/etc/php-fpm.d/www.conf
sed -i s/'group = www-data'/'group = username'/g /usr/local/etc/php-fpm.d/www.conf

I use this in my project and its working.

Upvotes: 1

Related Questions