Use IPython with Plone 6 in a plone-backend container

For those interested in using IPython with a plone-backend container.

Usage

git clone https://github.com/me-kell/plone_backend_with_ipython.git
cd plone_backend_with_ipython/
docker compose up -d
docker exec -e SITE_ID="Plone" my_container ./docker-entrypoint.sh create-classic
docker exec -it my_container ./docker-entrypoint.sh ipythonconsole

Project structure

.
├── compose.yaml
└── app
    ├── Dockerfile
    └── ipythonconsole

compose.yaml

services:
  backend_with_ipython:
    build:
      context: app
      target: builder
    image: plone-server-dev-with-ipython:latest
    container_name: my_container
    environment:
      ZEO_ADDRESS: zeo:8100
    ports: [ "8080:8080" ]
    depends_on: [ zeo ]
  zeo:
    image: plone/plone-zeo:6.0.0
    container_name: zeo
    restart: always
    volumes: [ data:/data ]
    ports: [ "8100:8100" ]
volumes:
  data: {}

app/Dockerfile

FROM plone/server-dev:6.1.1 AS builder
RUN gosu plone /app/bin/pip install ipython==9.2.0
COPY --chown=500:500 --chmod=755 ipythonconsole /app/bin/ipythonconsole
RUN sed -i '/^elif  \[\[ "$1" == "console" ]]; then/i elif  \[\[ "$1" == "ipythonconsole" ]]; then\n \ \ exec $sudo $VENVBIN/ipythonconsole etc/${CONF}' /app/docker-entrypoint.sh

app/ipythonconsole

#!/app/bin/python
# -*- coding: utf-8 -*-
import sys
import IPython
import Zope2
from Zope2.Startup.run import make_wsgi_app

if __name__ == '__main__':
    global_config = {}
    zope_conf = sys.argv[1]
    make_wsgi_app(global_config, zope_conf)
    app = Zope2.app()
    banner1 = (
        f'Starting IPython {IPython.__version__} '
        f'with zope_conf="{zope_conf}" and global_config="{global_config}"'
    )
    banner2 = f'The name "app" is bound to the top-level Zope object "{app}"'
    sys.exit(IPython.embed(colors="pride", banner1=banner1, banner2=banner2))

For details see GitHub - me-kell/plone_backend_with_ipython.