0
votes

I have an app in Laravel with .env.local file (a and I made the next docker-compose file:

api:
container_name: nadal_api
build:
  context: .
  dockerfile: Dockerfile
volumes:
  - .:/var/www/html/app
ports:
  - ${APP_PORT}:80
links:
  - db
  - redis

and my docker file

FROM composer:latest AS composer

FROM node:latest AS node

WORKDIR /var/www/html/app/

FROM php:7.2-fpm-stretch

RUN apt-get update && apt-get install -y \ supervisor \ nginx \ zip

ADD docker/nginx.conf /etc/nginx/nginx.conf ADD docker/virtualhost.conf /etc/nginx/conf.d/default.conf ADD docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

ARG enviroment

COPY --from=composer /usr/bin/composer /usr/bin/composer

COPY .env.local .env RUN chmod -R g+w /var/www/html/app/bootstrap

RUN composer install RUN php artisan key:generate

EXPOSE 80

CMD ["/usr/bin/supervisord"]

I want to clone the repository and when doing a docker-compose build that does the following in the dockerfile:

  1. rename .env.local to .env
  2. give permissions to the storage folder. I have an error in this line

RUN chmod -R g+w /var/www/html/app/bootstrap

chmod: cannot access '/var/www/html/app/bootstrap': No such file or directory

  1. docker-compose.yaml: ${APP_PORT} take values from .env.local (I tried with env_file but it does not work
1

1 Answers

2
votes

In your Dockerfile there is no COPY action to copy all your current project code into created image. Therefore bootstrap folder is not exist in your image. So chmod tells you exactly that.

Volumes (this line - .:/var/www/html/app) will sync your current directory with container later when it will be created depending on image structure. So if you want to give permissions to bootstrap folder then copy project code into image before giving permissions to it. Add this line before permission operations to make folders accessible.

COPY . /var/www/html/app