2

Im new to docker but i have read som guides and tried to create a docker image from my laravel project.

The docker command im running is

sudo docker build -t docker-image .

and this is my Dockerfile:

FROM composer:1.8.5 as build
WORKDIR /app
COPY . /app
RUN composer install

FROM php:7.3-apache
EXPOSE 80
COPY --from=build /app /app
COPY vhost.conf /etc/apache2/sites-available/000-default.conf
RUN chown -R www-data:www-data /app && a2enmod rewrite

The error comes during step 4/9 Run composer install:

[ErrorException]
file_put_contents(/app/vendor/bin/generate-defuse-key): failed to open stream: No such file or directory

the file exists in /vendor/bin/

can anyone tell me what i am doing wrong?

4
  • Are you open to use laravel with nginx? Commented Jun 11, 2019 at 12:00
  • @vikash, it's erroring before the apache step. Commented Jun 11, 2019 at 12:06
  • @pei-turn, Try building the composer step without running the install, then run the container and try to install manually from inside. That will give you better insight into what's going on. Commented Jun 11, 2019 at 12:08
  • @pei-turn just added the nginx docker settings for laravel application with docker-compose.. please do follow... let me know if you still getting any issue. Commented Jun 11, 2019 at 12:35

2 Answers 2

1

If you would like to run your laravel application with nginx you can use the following docker settings.

Here I supposed your application at: /var/www/laravelapp

So the file coposition would be as follow:

1. Your docker-compose file: /var/www/laravelapp/docker-compose.yml

version: "3.1"
services:
  webserver:
    image: nginx:alpine
    restart: always
    container_name: laravel-webserver
    working_dir: /application
    volumes:
        - /var/www/laravelapp:/application
        - /var/www/laravelapp/docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
    ports:
      - "82:80"
    env_file:
      - .env
    networks: 
      - intranet

  php-fpm:
    build: docker/php-fpm
    restart: always
    container_name: laravel-fpm
    working_dir: /application
    volumes:
      - /var/www/laravelapp:/application
    env_file:
      - .env
    networks: 
      - intranet

networks:
  intranet:
    external: false

2. Nginx dockerfile /var/www/laravelapp/docker/Dockerfile

FROM phpdockerio/php71-fpm:latest

# Install selected extensions and other stuff
RUN apt-get update \
    && apt-get -y --no-install-recommends install  php7.1-mysql php7.1-mbstring php7.1-gd git \
    && apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*


WORKDIR "/application"

3. Nginx host settings /var/www/laravelapp/docker/nginx/nginx.conf


server {
    listen 80 default;

    client_max_body_size 108M;

    access_log /var/log/nginx/application.access.log;


    root /application/public;
    index index.php;

    if (!-e $request_filename) {
        rewrite ^.*$ /index.php last;
    }

    location ~ \.php$ {
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        include fastcgi_params;
    }
    
}

Let me know if still you getting any issue.

Sign up to request clarification or add additional context in comments.

1 Comment

@JamesBond this is the complete configuration for running laravel project with docker.
0

I found the problem it was not a docker, composer or laravel problem but a git problem. the problem was that git could not create a symlink and i missed the error when checking out the project. i found it when i did all the steps again.

Comments

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.