Skip to content

Instantly share code, notes, and snippets.

@andyshinn
Last active February 18, 2024 12:05
Show Gist options
  • Select an option

  • Save andyshinn/e2c428f2cd234b718239 to your computer and use it in GitHub Desktop.

Select an option

Save andyshinn/e2c428f2cd234b718239 to your computer and use it in GitHub Desktop.
Docker Compose PHP Composer Example
{
"require": {
"mfacenet/hello-world": "v1.*"
}
}
app:
restart: 'yes'
image: php:7
command: php -S 0.0.0.0:8000 /app/index.php
ports:
- "8000:8000"
volumes:
- .:/app
composer:
restart: 'no'
image: composer/composer:php7
command: install
volumes:
- .:/app
<?php
require 'vendor/autoload.php';
use HelloWorld\SayHello;
echo SayHello::world();
@vinaydotblog

Copy link
Copy Markdown

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

@blachawk

blachawk commented Mar 6, 2018

Copy link
Copy Markdown

what does this mean in detail?

  command: php -S 0.0.0.0:8000 /app/index.php

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

@mereba

mereba commented Mar 9, 2018

Copy link
Copy Markdown

@blachawk, command: php -S 0.0.0.0:8000 /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.

@puku

puku commented Jun 13, 2018

Copy link
Copy Markdown

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.

@killrazor

killrazor commented Jun 21, 2018

Copy link
Copy Markdown

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.

And...it appears that the remote repository no longer exists.

[tyler.christian@ThisOne my-dir]$ git clone git@github.com:mfacenet/hello-world.git
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.

@otech-nl

Copy link
Copy Markdown

Thanks!

It just works (TM)

@thalysonalexr

Copy link
Copy Markdown

Thanks, worked for me!

@jonathansanchez

Copy link
Copy Markdown

@andyshinn How does it work with PHP 7.2?

@andyshinn

Copy link
Copy Markdown
Author

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

@samo29

samo29 commented Feb 19, 2020

Copy link
Copy Markdown

Perfect! thanks for share!

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