Skip to content

Commit

Permalink
docs: building Docker images (#75)
Browse files Browse the repository at this point in the history
* Add docs for custom docker image

* docs: improve Docker documentation

* more docs

Co-authored-by: Kévin Dunglas <[email protected]>
  • Loading branch information
alexander-schranz and dunglas authored Nov 3, 2022
1 parent 9ef3bd7 commit 3641552
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 14 deletions.
31 changes: 31 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@ The server is listening on `127.0.0.1:8080`:

curl -v http://127.0.0.1:8080/phpinfo.php

# Building Docker Images Locally

Print bake plan:

```
docker buildx bake -f docker-bake.hcl --print
```

Build FrankenPHP images for amd64 locally:

```
docker buildx bake -f docker-bake.hcl --pull --load --set "*.platform=linux/amd64"
```

Build FrankenPHP images for arm64 locally:

```
docker buildx bake -f docker-bake.hcl --pull --load --set "*.platform=linux/arm64"
```

Build FrankenPHP images from scratch for arm64 & amd64 and push to Docker Hub:

```
docker buildx bake -f docker-bake.hcl --pull --no-cache --push
```

## Misc Dev Resources

* [PHP embedding in uWSGI](https://github.com/unbit/uwsgi/blob/master/plugins/php/php_plugin.c)
Expand All @@ -63,3 +89,8 @@ The server is listening on `127.0.0.1:8080`:
* [What the heck is TSRMLS_CC, anyway?](http://blog.golemon.com/2006/06/what-heck-is-tsrmlscc-anyway.html)
* [PHP embedding on Mac](https://gist.github.com/jonnywang/61427ffc0e8dde74fff40f479d147db4)
* [SDL bindings](https://pkg.go.dev/github.com/veandco/[email protected]/sdl#Main)

## Docker-Related Resources

* [Bake file definition](https://docs.docker.com/build/customize/bake/file-definition/)
* [docker buildx build](https://docs.docker.com/engine/reference/commandline/buildx_build/)
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ Go to `https://localhost`, and enjoy!
* [Early Hints support (103 HTTP status code)](docs/early-hints.md)
* [Real-time](docs/mercure.md)
* [Configuration](docs/config.md)
* [Docker images](docs/docker.md)
* [Compile from sources](docs/compile.md)
* [Building Docker images](docs/docker.md)
* [Demo app (Symfony) and benchmarks](https://github.com/dunglas/frankenphp-demo)
* [Go library documentation](https://pkg.go.dev/github.com/dunglas/frankenphp)
* [Contributing and debugging](CONTRIBUTING.md)

Expand Down
76 changes: 63 additions & 13 deletions docs/docker.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,80 @@
# Building Docker Images
# Building Custom Docker Image

Print bake plan:
[FrankenPHP Docker images](https://hub.docker.com/repository/docker/dunglas/frankenphp) are based on [official PHP images](https://hub.docker.com/_/php/). Alpine Linux and Debian variants are provided for popular architectures.

```
docker buildx bake -f docker-bake.hcl --print
## How to Use The Images

Create a `Dockerfile` in your project:

```Dockerfile
FROM dunglas/frankenphp

COPY . /app/public
```

Build FrankenPHP images for amd64 locally:
Then, run the commands to build and run the Docker image:

```
docker buildx bake -f docker-bake.hcl --pull --load --set "*.platform=linux/amd64"
$ docker build -t my-php-app .
$ docker run -it --rm --name my-running-app my-php-app
```

Build FrankenPHP images for arm64 locally:
## How to Install More PHP Extensions

The [`docker-php-extension-installer`](https://github.com/mlocati/docker-php-extension-installer) script is provided in the base image.
Adding additional PHP extensions is straightforwardd:

```dockerfile
FROM dunglas/frankenphp

# add additional extensions here:
RUN install-php-extensions \
pdo_mysql \
gd \
intl \
zip \
opcache

# ...
```
docker buildx bake -f docker-bake.hcl --pull --load --set "*.platform=linux/arm64"

# Enabling the Worker Mode by Default

Set the `FRANKENPHP_CONFIG` environment variable to start FrankenPHP with a worker script:

```Dockerfile
FROM dunglas/frankenphp

# ...

ENV FRANKENPHP_CONFIG="worker ./public/index.php"
```

Build FrankenPHP images from scratch for arm64 & amd64 and push to Docker Hub:
# Using a Volume in Development

To develop easily with FrankenPHP, mount the directory from your host containing the source code of the app as a volume in the Docker container:

```
docker buildx bake -f docker-bake.hcl --pull --no-cache --push
docker run -v $PWD:/app/public -p 80:80 -p 443:443 my-php-app
```

## Resources
With Docker Compose:

* [Bake file definition](https://docs.docker.com/build/customize/bake/file-definition/)
* [docker buildx build](https://docs.docker.com/engine/reference/commandline/buildx_build/)
```yaml
# docker-compose.yml

version: '3.1'

services:

php:
image: dunglas/frankenphp
# uncomment the following line if you want to use a custom Dockerfile
#build: .
restart: always
ports:
- 80:80
- 443:443
volumes:
- ./:/app/public
```

0 comments on commit 3641552

Please sign in to comment.