Home > Software design >  Docker install and use composer with laravel and dependencies
Docker install and use composer with laravel and dependencies

Time:09-20

Im startig my journal with docker.

I made docker-compose.yml that starts following services:

  • nginx
  • PHP 8.1

I setup site to display and read php files, everything is ok. But right now I don't know whats next. I want to install laravel with composer and NPM. How to run it together in that way I can user "composer install", "composer update" in every project.

This is my docker-compose.yml:


services:
  nginx:
    container_name: nginx_tst
    image: nginx:latest
    networks:
      - php
    ports:
      - "8080:80"
    volumes:
      - "./nginx-conf:/etc/nginx/conf.d"
      - "./:/usr/share/nginx/html"

  php:
    container_name: php_tst
    image: php:8.1-fpm
    networks:
      - php
    volumes:
      - "./:/usr/share/nginx/html"
    working_dir: /

networks:
  php:

CodePudding user response:

Add command attribute to the php service. Using that you can execute compose install and update commands and etc...

Follow this link to know how to execute multiple commands

Docker Compose - How to execute multiple commands?

You can use something like this.

command: curl -s https://laravel.build/example-app | bash

CodePudding user response:

You can go inside the container

docker exec -it php_tst bash

and then install & run composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
php composer.phar install

install & run nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

nvm install node
node -v
npm i 
npm run dev
  • Related