-1

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:

Edit:

I Switched to Laravel Sail, it makes everything by itself
Screeaam
  • 31
  • 7

2 Answers2

1

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
YJR
  • 1,099
  • 3
  • 13
-1

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
valetzyzy
  • 58
  • 7
  • Is it good practice? What happen when I restart linux? Installation still will be there or I have to do this steps everytime I restart linux? – Screeaam Sep 20 '22 at 14:23
  • This is not a good practice; anything you do in this `docker exec` shell will get lost as soon as the container exits. I'd suggest using `docker exec` sparingly: it's a very useful debugging tool but it shouldn't usually be part of your core workflow. – David Maze Sep 20 '22 at 14:44
  • So how to use composer correctly on docker? – Screeaam Sep 20 '22 at 14:49
  • @DavidMaze for local developments it's totally ok, any suggestions on how to use it in the proper way? – valetzyzy Sep 21 '22 at 14:27