Docker Community Forums

Share and learn in the Docker community.

ENTRYPOINT chmod

I’m currently building an image for production where I copy in the source code for my web project. In order for it to work successfully, I need to CHMOD a folder inside the container to 777.

I’ve tried dozens of variation of ENTRYPOINT scripts, but lack of knowledge and understanding are in the way.

FROM php:7.0-apache

Install modules

RUN apt-get update && apt-get install -y
php5-mysql
libmcrypt-dev
&& docker-php-ext-configure mbstring --enable-mbstring
&& docker-php-ext-install pdo_mysql mcrypt mbstring
RUN a2enmod rewrite
#RUN a2enmod ssl
RUN apt-get update && apt-get install nano

COPY $PWD/ /var/www/html/
USER root
ENTRYPOINT [“bash”, “-c”, “chmod 777 /var/www/html/wpcodes/portal/data/cache”]
#COPY ./docker-entrypoint.sh /usr/local/bin/
#RUN chmod +x /usr/local/bin/docker-entrypoint.sh
#WORKDIR /var/www/html/wpcodes/portal/data
#RUN chmod 777 /var/www/html/wpcodes/portal/data/cache
#ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh", “bin/bash”]
#WORKDIR /var/www/html/wpcodes/portal/data
#ENTRYPOINT [“sudo chmod”, “777”]
#CMD [“var/www/html/wpcodes/portal/data”]
#ENTRYPOINT exec chmod 777 /var/www/html/wpcodes/portal/data
#ENTRYPOINT ["/bin/bash", “chmod 777 /var/www/html/wpcodes/portal/data”]
#CMD ["", “-l”]
#RUN chmod 777 /var/www/html/wpcodes/portal/data
#RUN chmod 777 /var/www/html/wpcodes/portal/data/cache
#RUN chmod 777 /var/www/html/wpcodes/portal/data/public
#RUN chmod 777 /var/www/html/wpcodes/portal/new-rewrite

EXPOSE 80 443

The error I’m getting from the above file:

chmod: cannot access ‘/var/www/html/wpcodes/portal/data/cache’: No such file or directory

I tried to change the user, but that didn’t help.

When I bash into the container and use the command it works as needed. I need to have the CHMOD permissions changed inside the script. Thanks for your help.

try instead

COPY . /var/www/html/
RUN chmod 777 -R /var/www/html/wpcodes/portal/data/cache

Thanks for the reply. Issue still remains. See output below.

Step 6/8 : COPY . /var/www/html/
—> 98954fdaa3d6
Removing intermediate container c9e0167a0979
Step 7/8 : RUN chmod 777 -R /var/www/html/wpcodes/portal/data/cache
—> Running in b5622758266a
chmod: cannot access ‘/var/www/html/wpcodes/portal/data/cache’: No such file or directory

^this now depends on your build process…cannot know what is under your current directory, where the Dockerfile is. There should be a wpcodes/portal/data/cache directory otherwise it will fail.

Fair point. The URL is correct, once the copy happens the URL is correct in the container. I’ve validated this by bashing into the container and running PWD on the directory specified.

so your intermediate image is 98954fdaa3d6 as you write above in your message.

just do a docker run -ti 98954fdaa3d6 bash -c "ls -lisa /var/www/html" to see what actually has been copied. Then step by step to to modify it to the chmod you want. Once this works, you can add the bash command into your Dockerfile and it just will work.

Thanks for the command. Here is the output. The files are in there.

I agree that the RUN command should work, but is there a reason that an ENTRYPOINT command would be required to CHMOD the folder?

so the wpcodes folder is missing?

yes, i also still doubt that the chmod is necessary, but first get your image to work, then simplify/beautify it. :slight_smile:

HAHA. I read that so many times. Part of me feels sad inside the happiness. Thanks for your help, really appreciate it.

Thanks for the help!