Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

georgetown74's avatar

How do I run Composer command with Docker?

I am new to PHP and Laravel. I am trying to follow along with the "Laravel 8 From Scratch" tutorial. In Episode 12 I am asked to install YAML Front Matter using Composer using the command "composer require spatie/yaml-front-matter". When I try that I get an error message: "zsh: command not found: composer". In Episode 2 on "Initial Environment Setup and Composer" it looks like the instructions provided for setting up Composer only apply if you are using the "local" setup option, but I chose to use the Docker Desktop option specified in "Getting Started On macOS" (https://laravel.com/docs/9.x/installation#getting-started-on-macos). Can someone please explain how I can install the YAML Front Matter code and/or install Composer with the Docker Desktop configuration option? Thanks!

0 likes
3 replies
Sergiu17's avatar
Sergiu17
Best Answer
Level 60

https://docs.docker.com/engine/reference/commandline/exec/

you should run composer install from your docker container

// list  your running containers
docker ps

// container_name is a placeholder, change it with information from previous command
docker exec -ti {container_name} bash

or you use docker desktop to execute commands from a specific container

georgetown74's avatar

Perfect, that's exactly what I needed. Thank you so much for the prompt, helpful reply!

1 like
aosdev's avatar

I'm using it like;

docker run --rm \
    -u "$(id -u):$(id -g)" \
    -v $(pwd):/var/www/html \
    -w /var/www/html \
    laravelsail/php81-composer:latest \
    composer install --ignore-platform-reqs

Please or to participate in this conversation.