当前位置: 动力学知识库 > 问答 > 编程问答 >

ERROR: mkdir with chown not working in Dockerfile (nginx with php-fpm)

问题描述:

For version control and security I want to merge two Dockerfiles into one and then create a directory for .sock => running rmdir and chown.

Without rmdir and chown, I can perfectly build the docker if run over port:9000. As soon as I try setting up the directory for .sock, in the dockerfile, the docker build process exits. All Details below. Thanks a ton for any help.

1st Dockerfile half

FROM debian:jessie

ENV NGINX_VERSION 1.11.6-1~jessie

RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 \

&& echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list \

&& apt-get update \

&& apt-get install --no-install-recommends --no-install-suggests -y \

ca-certificates \

nginx=${NGINX_VERSION} \

nginx-module-xslt \

nginx-module-geoip \

nginx-module-image-filter \

nginx-module-perl \

nginx-module-njs \

gettext-base \

&& rm -rf /var/lib/apt/lists/*

# forward request and error logs to docker log collector

RUN ln -sf /dev/stdout /var/log/nginx/access.log \

&& ln -sf /dev/stderr /var/log/nginx/error.log

EXPOSE 80 443

#CMD ["nginx", "-g", "daemon off;"]

2nd Dockerfiel half

with this PHP code and the respective files one level above this code.

I don't expose the 9000 port and comment out the CMD.

All is then managed through supervisord.

I build it with help of docker-compose

version: '2'

services:

web:

build:

context: ../../builds/nx1116Php71RC6Comp123_J

dockerfile: Dockerfile

image:

tl_nx1116php71rc6comp123:v1

#mounts HOST:CONTAINER (the actual server to the container system)

volumes:

#nginx

- ../../data/nxphp/nginx1116/html:/usr/share/nginx/html

- ../../data/nxphp/nginx1116/conf.d:/etc/nginx/conf.d

- ../../logs/nxphp:/var/log/nginx

#PHP

- ../../data/nxphp/php71fpm/etc:/usr/local/etc

# - ../../logs/nxphp/php71fpm:?????

#Supervisor

- ../../data/nxphp/supervisor/supervisor.conf:/etc/supervisor.conf

- ../../logs/supervisor:/var/log/supervisor

#foward port HOST:CONTAINER

ports:

- "80:80"

- "443:443"

When I run it like that, set up php and nginx confs to work with 9000 all works fine.

BUT I want to talk to .sock. There is none, so I need to create a/the directory, where nginx can put it. Thus in my mind I put at the end of my docker file

RUN set -xe \

mkdir -p /var/run/php-fpm

&& chown www-data:www-data /var/run/php-fpm

yet that always ends with a building error. and when i exec into the partially build docker image, i cannot find /var/run/php-fpm. I also tried putting it just into /run, but had the same result. Making two RUN commands from it "works" in that way, that I have no error, but the folder still does not exist and then obviously my image quits that it cannot find .sock folder.

&& { echo '[global]'; echo 'daemonize = no'; echo; echo '[www]'; echo 'listen = [::]:9000'; } | tee php-fpm.d/zz-docker.conf

---> Using cache

---> 609c93af398d

Step 22 : RUN set -xe mkdir -p /var/run/php-fpm && chown www-data:www-data /var/run/php-fpm

---> Running in de4b7443a82a

+ chown www-data:www-data /var/run/php-fpm

chown: cannot access '/var/run/php-fpm': No such file or directory

ERROR: Service 'web' failed to build: The command '/bin/sh -c set -xe mkdir -p /var/run/php-fpm && chown www-data:www-data /var/run/php-fpm' returned a non-zero code: 1

Any help would be highly appreciated

网友答案:

You have two errors on this line:

RUN set -xe \
    mkdir -p /var/run/php-fpm
    && chown www-data:www-data /var/run/php-fpm

The first is that mkdir is an arg of set without the && separator. And the second is that && chown ... is treated as a dockerfile command since the previous line ended without an \. Here's the corrected syntax:

RUN set -xe \
 && mkdir -p /var/run/php-fpm \
 && chown www-data:www-data /var/run/php-fpm
分享给朋友:
您可能感兴趣的文章:
随机阅读: