Docker image + bedrock & sage

My trip into trying to get bedrock + sage to work on a WSL2 + Ubuntu + Docker setup has been quite the nightmare.

Roots offers an official docker image: GitHub - roots/bedrock-docker: https://roots.io/bedrock/

This is php8.0 image and I have got it working up untill the prompt to install Acorn. However, installing Acorn upgrades the composer dependency of php to 8.1. This breaks everything in the docker image.

I have tried to manually upgrade the image to php8.1 but this creates a lot of problems with extensions and dependencies for laravel etc.

I have tried a lot of different setups via Google, even create an official php image, and Iā€™m now counting 4 full days of troubleshooting.

Does anyone have any pointers to a dockerfile & docker-compose.yml that actually works with bedrock+sage, Iā€™d be very grateful.

Hi @hum,

Weā€™ve had success with the runtime images taken from the Bitpoke stack. They provide Bedrock-specific containers with PHP-FPM and Nginx. These images are intended as a production runtime on K8s, but will work for Docker.

https://hub.docker.com/r/bitpoke/wordpress-runtime/tags?page=1&name=bedrock

Creating a docker-compose.yml with a MySQL service should be fairly trivial after that.

Iā€™m not advocating this approach for production, but if you want to bundle Node and some other dev tooling into the image, you might be able to cannibalise this. This can be useful if you want a fully isolated dev container. This dockerfile uses multi-stage builds: runtime without dev tooling, and dev with node / mysql-client.

Thank you!

Iā€™ll look into the Bitpoke stack. And indeed, Iā€™m intending to use this only for local development.

You may find this also interesting:

This looks really nice! Sadly I need a php8.1+ image.

How would you recommend upgrading your image to 8.1?

Yes, I had not looked into this for a few months now. As I now also migrated everything to PHP 8.1, it is time to update those images. :smile_cat:

@strarsis pull access denied for strarsis/php-bedrock, repository does not exist or may require ā€˜docker loginā€™: denied: requested access to the resource is denied

docker pull strarsis/docker-php-bedrock:8.0.1-fpm
(https://hub.docker.com/layers/strarsis/docker-php-bedrock/8.0.1-fpm/images/sha256-b910666b2f556733098210b0fbd91b6af8072b1cdc0790ce39f5e1d456c278ae?context=repo)

DockerHub currently does not automatically build from (GitHub) source?
PHP 8.1; 8.2 and 8.3 branches were added to GitHub repository:

1 Like

@meha, @jasperfrumau: I built and pushed images for PHP 7.4; 8.0; 8.1; 8.2 and 8.3 to Docker Hub, you can pull these from there:
https://hub.docker.com/r/strarsis/docker-php-bedrock/tags

1 Like

Awesome. Thanks @strarsis ! Will use it on my new Raspberry Pi 500 in a project side by side with Trellis

project
-- container
-- site
--  trellis
README.md
LICENSE

This way I can work on it with Docker on the Raspberry Pi and on my Mac using limactl.

Only need to see how Trellis command line tool could work on Linux so I can use it there to deploy changes as well. Or some other wayā€¦

By the way, the test for PHP 8.3 seems to load 8.1 at docker-php-bedrock/test/compose/container/docker-compose.yml at aa40134a10fa8a72574880eb6f6082c6b6e0766b Ā· strarsis/docker-php-bedrock Ā· GitHub

Also, see the images are AMD64 so may need to build my own for ARM64 but not sure. Will check.

Made a new setup based on @strarsis one for ARM 64 with with php composer and node added including yarn and Volta . Node in separate container See imagewize.com/container at main Ā· imagewize/imagewize.com Ā· GitHub and here main docker-compose-yml:

services:

  php:
    build:
      context: ../container
      dockerfile: Dockerfile
    volumes:
      - ../site:/srv/www
      - /tmp:/tmp
      - node_binaries:/usr/local/node:ro  # Added read-only flag
      - volta_home:/usr/local/volta:ro
    environment:
      - PATH=/usr/local/node/bin:/usr/local/volta/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      - VOLTA_HOME=/usr/local/volta
    networks:
      - app-network
    depends_on:
      - node

  nginx:
    image: nginx:1.19.2
    volumes:
      - ../site:/srv/www
      - ./nginx/config/app.conf:/etc/nginx/conf.d/default.conf
    ports:
      - "8080:80"
    networks:
      - app-network
    depends_on:
      - php

  db:
    image: mariadb:10.5
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: app
      MYSQL_USER: app
      MYSQL_PASSWORD: test
    ports:
      - "3307:3306"
    volumes:
      - ./db/data:/var/lib/mysql
    networks:
      - app-network

  node:
    build:
      context: ../container/node
      dockerfile: Dockerfile
    volumes:
      - ../site:/srv/www
      - node_binaries:/usr/local/node
      - volta_home:/usr/local/volta
    environment:
      - PATH=/usr/local/node/bin:/usr/local/volta/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      - VOLTA_HOME=/usr/local/volta
    tty: true
    stdin_open: true
    command: tail -f /dev/null
    networks:
      - app-network

volumes:
  node_binaries:
  volta_home:

networks:
  app-network:
    driver: bridge



The Trellis/WordPress stack should run fine on arm (including arm servers),
see this discussion:

1 Like

Main remaining issue now is bud.config.js to make the development server load on localhost:3000

...
app
    .setUrl('http://localhost:3000')
    .setProxyUrl('http://site.test')
    .watch(['resources/views', 'app']);
...

with site url set in /etc/hosts works for site loading under http://site.test, but I cannot get dev server to load under http://localhost:3000

docker-compose.yml I have now is

services:

  php:
    build:
      context: ../container
      dockerfile: Dockerfile
    volumes:
      - ../site:/srv/www
      - /tmp:/tmp
      - node_binaries:/usr/local/node:ro  # Added read-only flag
      - volta_home:/usr/local/volta:ro
    environment:
      - PATH=/usr/local/node/bin:/usr/local/volta/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      - VOLTA_HOME=/usr/local/volta
    networks:
      - app-network
    depends_on:
      - node

  nginx:
    image: nginx:1.19.2
    volumes:
      - ../site:/srv/www
      - ./nginx/config/app.conf:/etc/nginx/conf.d/default.conf
    ports:
      - "80:80"
    networks:
      - app-network
    depends_on:
      - php

  db:
    image: mariadb:10.5
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: app
      MYSQL_USER: app
      MYSQL_PASSWORD: test
    ports:
      - "3307:3306"
    volumes:
      - ./db/data:/var/lib/mysql
    networks:
      - app-network

  node:
    build:
      context: ../container/node
      dockerfile: Dockerfile
    volumes:
      - ../site:/srv/www
      - node_binaries:/usr/local/node
      - volta_home:/usr/local/volta
    environment:
      - PATH=/usr/local/node/bin:/usr/local/volta/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      - VOLTA_HOME=/usr/local/volta
    tty: true
    stdin_open: true
    command: tail -f /dev/null
    ports:
      - "3000:3000"
    networks:
      - app-network

volumes:
  node_binaries:
  volta_home:

networks:
  app-network:
    driver: bridge

running yarn dev from node container works but cannot load localhost:3000 in browser and

jasper@raspberrypi:~/code/site.com/container $ curl  -I http://localhost:3000
curl: (56) Recv failure: Connection reset by peer

tried

.setPublicUrl('http://site.test:3000');

as well but did not seem to change things. Then when I used 0.0.0.0

.setUrl('http://0.0.0.0:3000')

I hit a

BudError 

āœ˜ [HPM] Error occurred while proxying request %s to %s [%s] (%s)

on loading localhost:3000

Perhaps I need to adjust Nginx settingsā€¦ or expose ports differently. No idea yet.

1 Like

Think I managed to solve it using PORT=3000 and network_mode: host (container using host network)

...
node:
    build:
      context: ../container/node
      dockerfile: Dockerfile
    volumes:
      - ../site:/srv/www
      - node_binaries:/usr/local/node
      - volta_home:/usr/local/volta
    environment:
      - PATH=/usr/local/node/bin:/usr/local/volta/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      - VOLTA_HOME=/usr/local/volta
      - HOST=127.0.0.1
      # This port informs our dev server to listen on port 3000
      - PORT=3000
    network_mode: host
    working_dir: /srv/www/web/app/themes/nynaeve
    tty: true
    stdin_open: true
...

That and this block for Nginx

...
location /bud/ {
  proxy_pass http://127.0.0.1:3000;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
  proxy_set_header Host $host;
}
...

thanks to Bud.js Hot Loading with DDEV Container Setup - Citation Media .

Hot reloading is working. Whether this is the best way or not remains to be seen, but for now for local development this works and yarn dev can be run in the node container as well

1 Like

@strarsis how do you do logging of errors, PHP errors mainly? Did not see debug path details added for that in docker-php-bedrock/test/compose/.env at aa40134a10fa8a72574880eb6f6082c6b6e0766b Ā· strarsis/docker-php-bedrock Ā· GitHub . Do you perhaps do it a Docker way? Considering my options.