Run nginx and php into containers with proper user for development

前端 未结 2 1311
悲哀的现实
悲哀的现实 2021-02-11 09:38

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 gr

2条回答
  •  清酒与你
    2021-02-11 10:14

    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.

提交回复
热议问题