Skip to content

Instantly share code, notes, and snippets.

Last active February 18, 2024 12:05
Show Gist options
  • Save andyshinn/e2c428f2cd234b718239 to your computer and use it in GitHub Desktop.
Save andyshinn/e2c428f2cd234b718239 to your computer and use it in GitHub Desktop.
Docker Compose PHP Composer Example
"require": {
"mfacenet/hello-world": "v1.*"
restart: 'yes'
image: php:7
command: php -S /app/index.php
- "8000:8000"
- .:/app
restart: 'no'
image: composer/composer:php7
command: install
- .:/app
require 'vendor/autoload.php';
use HelloWorld\SayHello;
echo SayHello::world();
Copy link

jarrettj commented Feb 2, 2017


Thanks for gist.

If I run 'docker-compose run composer install', it creates a new containter, instead of using the defined one.

It works, just that you get plenty of stopped containers in kitematic with names like composer_composer_1 and so on.

Is that normal behavior? Thanks.

Copy link

Maybe try docker-compose exec composer install. This should run the command in an already running container.

Copy link

lighter commented May 11, 2017

Hi, I run this command docker-compose run --rm composer install on my service(I ssh to my service). And I got the error message [RuntimeException]/var/www/html/vendor does not exist and could not be created.. But I run this command on my Mac, it's work. I miss something? Thanks.

Copy link

Sweet and simple! Thank you so much for this gist!

Copy link

blachawk commented Mar 6, 2018

what does this mean in detail?

  command: php -S /app/index.php

Looks port relatd, but you are already setting the port on the very next line.

Copy link

mereba commented Mar 9, 2018

@blachawk, command: php -S /app/index.php means use php inside the app container to start a web server running at port 8000 that executes /app/index.php. The very next line reads like this: expose port 8000 from the host machine, to port 8000 where the web server is running in the container. So that you can navigate to http://localhost:8000 in your browser and see what /app/index.php shows or does.

Copy link

puku commented Jun 13, 2018

Hi guys,

Thanks for the gist

Can you advice how it's better to use composer container when you application need to run composer inside it's own container?
For example, if you use symfony/phpunit-bridge to run tests, it try to install required packages.

Copy link

killrazor commented Jun 21, 2018

Restart policy of 'yes' is not valid (at least now) docker restart policies.
Also, I had to use docker-compose up to install the container. appears that the remote repository no longer exists.

[tyler.christian@ThisOne my-dir]$ git clone
Cloning into 'hello-world'...
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Copy link


It just works (TM)

Copy link

Thanks, worked for me!

Copy link

@andyshinn How does it work with PHP 7.2?

Copy link

Is there some error with PHP 7.2? I don't use PHP daily so I am not sure what the difference might be.

Copy link

samo29 commented Feb 19, 2020

Perfect! thanks for share!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment