Distributing Laravel Zero apps with Docker

(updated )

I've recently started distributing my Laravel Zero applications with Docker. Laravel Zero already supports generating Phar files using Box, and Box supports generating a Dockerfile from a Phar.

In Laravel Zero, this is as easy as running the following command:

vendor/laravel-zero/framework/bin/box docker

The generated Dockerfile will look like this:

FROM php:8.0-cli-alpine

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/

RUN install-php-extensions zlib

COPY builds/application /application

ENTRYPOINT ["/application"]

This allows you to install any required dependencies as part of the run block, for example if you required the OAuth and GD extensions:

RUN docker-php-ext-install zlib oauth gd

Note: The zlib extension is required for GZ compression with Box, if you are using this.

Once this has been generated, you can try building your Docker image with:

docker build -t application .

If everything works as expected, you can try running your built image with Docker using:

docker run --rm application

I personally like to store my built Docker images on GitHub Container Repository (GHCR). If you want to set this up, you can use this GitHub Action workflow.

name: Docker

            - 'v*'

        runs-on: ubuntu-latest
            contents: read
            packages: write
        name: Build

            -   name: Checkout
                uses: actions/[email protected]

            -   name: Login to Docker Hub
                uses: docker/[email protected]
                    registry: ghcr.io
                    username: ${{ github.repository_owner }}
                    password: ${{ secrets.GITHUB_TOKEN }}

            -   name: Set up Docker Buildx
                uses: docker/[email protected]

            -   name: Extract metadata (tags, labels) for Docker
                id: meta
                uses: docker/[email protected]
                    images: ghcr.io/${{ github.repository }}
                    tags: |

            -   name: Build and push
                uses: docker/[email protected]
                    context: .
                    push: true
                    platforms: linux/amd64,linux/arm64
                    tags: ${{ steps.meta.outputs.tags }}
                    labels: ${{ steps.meta.outputs.labels }}

For other ways to distribute your Laravel Zero applications, check out my blog posts on Distributing Laravel Zero apps with Windows package managers, and Distributing Laravel Zero apps with Brew.

1 2 0 2