Skip to content

Commit

Permalink
add docker-compose.yml to php example
Browse files Browse the repository at this point in the history
  • Loading branch information
Don Townsend committed Oct 12, 2020
1 parent 8949aeb commit f28d2aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 12 additions & 4 deletions example-php-apache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,28 @@ Follow these steps to start the php server:
```
cd /path/to/example-php-apache
docker build -t example-php-apache-img .
docker run -p 3000:80 -v $(pwd)/src:/var/www/html --name example-php-apache-container example-php-apache-img
docker run -p 8000:80 -v $(pwd)/src:/var/www/html --name example-php-apache-container example-php-apache-img
```

Open up the following url in your browser:

- http://localhost:3000
- http://localhost:8000


# Notes
#### Notes about `docker run`:

In the `docker run` command:
- `-p` maps ports like so: `<MACHINE_PORT>:<CONTAINER_PORT>`
- `-v` specifies the volume to enable realtime updates in local dev environment.
- The volume must be specified at runtime in order for this to work. [See documentation](https://docs.docker.com/engine/reference/builder/#notes-about-specifying-volumes) for more details.
- The host volume mount src MUST be absolute, not relative
- `$(pwd)` just outputs the absolute path of the present working directory
- Volumes have ZERO effect once deployed (except for sharing filesystems across several containers)

## Docker Compose

All of the above can steps can be simplified into a single cmd that utilizes docker compose:

```
cd /path/to/example-php-apache
docker-compose up
```
9 changes: 9 additions & 0 deletions example-php-apache/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "3"

services:
webapp:
build: .
volumes:
- ./src:/var/www/html
ports:
- "8000:80"

0 comments on commit f28d2aa

Please sign in to comment.