0

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 Dockerfile:

FROM composer:latest AS composer

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 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks, it worked. Do you know abour ${APP_PORT} ? I need .env.local instead of .env
Why you need copy and rename? When you copy the entire project then .env also copied into the container. So before begin building just edit your environment based values in .env file all will be fine :)
.env is ignored file because of your all secret informations will be inside of this file. You can find that it added inside .gitignore file. So if you want your config to work for your app just copy .env.example file as .env and add your configurations. Then start image building prosess. Then there will be .env file there) and you can use all env variables inside your containers.
If you add the line in my answer then all. Files in your app will be inside your image. So that composer.json file also will be there. And because of you set WORKDIR correctly running composer install must add all vendor files into image. Also I can not try now copying but I guess your copy will create correct .env file inside image. If no then after adding the line in my answer just use linux move command to rename file. RUN mv .env.local .env then there will be renamed .env file:)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.