Skip to content

Commit f1fbc85

Browse files
linawolfsfinnerWco
andauthored
[TASK] Demonstrate how to extend a docker image (#5659)
* [TASK] Demonstrate how to extend a docker image Releases: main, 13.4, 12.4 * [TASK] Demonstrate how to extend a docker image Releases: main, 13.4, 12.4 * Update Documentation/Administration/Docker/AutomateSetup/Index.rst Co-authored-by: Sven Finner <[email protected]> * Update Documentation/Administration/Docker/AutomateSetup/Index.rst Co-authored-by: Sven Finner <[email protected]> * Update Documentation/Administration/Docker/AutomateSetup/Index.rst --------- Co-authored-by: Sven Finner <[email protected]>
1 parent 1e9cb5c commit f1fbc85

File tree

6 files changed

+441
-0
lines changed

6 files changed

+441
-0
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
:navigation-title: Automate TYPO3 Setup
2+
3+
.. include:: /Includes.rst.txt
4+
.. _docker-cli-automated-setup:
5+
6+
==================================
7+
Automate TYPO3 setup using the CLI
8+
==================================
9+
10+
This section demonstrates how to fully automate a TYPO3 installation using the CLI
11+
command `typo3 setup`, removing the need to complete the install wizard in the
12+
browser.
13+
14+
This is particularly useful for repeatable local setups, CI pipelines, or scripted
15+
Docker environments.
16+
17+
.. note::
18+
19+
While this example uses a classic TYPO3 installation based on the
20+
`martinhelmich/typo3` image, the same approach can be adapted for
21+
Composer-based projects. To do so, use a different base image (e.g.
22+
`php:8.4-apache`) and update the CLI path to match the Composer installation,
23+
typically `vendor/bin/typo3`.
24+
25+
.. contents:: Table of contents
26+
27+
.. _docker-cli-automated-setup-dockerfile:
28+
29+
Update the Dockerfile to install gosu and Node.js
30+
=================================================
31+
32+
Extend the Dockerfile to install `gosu`, which enables secure user switching, and include the `startup.sh` script to automate the setup process.
33+
34+
.. literalinclude:: _codesnippets/_Dockerfile
35+
:language: docker
36+
:caption: Dockerfile
37+
38+
.. _docker-cli-automated-setup-startup:
39+
40+
Create a startup script that runs TYPO3 setup
41+
=============================================
42+
43+
The startup script checks if TYPO3 has already been installed. If not, it runs
44+
the `typo3 setup` CLI command in non-interactive mode using environment
45+
variables defined in Docker Compose.
46+
47+
.. literalinclude:: _codesnippets/_startup.sh
48+
:language: bash
49+
:caption: startup.sh
50+
51+
This script:
52+
53+
- Detects if TYPO3 has already been installed
54+
- Runs the CLI-based `setup` command only once
55+
- Starts Apache in the foreground as required for Docker
56+
57+
.. note::
58+
59+
The `gosu` command is used instead of `su` to preserve environment variables
60+
passed by Docker Compose. Without this, the `typo3 setup` command would not
61+
receive the necessary database and admin credentials.
62+
63+
.. tip::
64+
65+
If you see this message in the logs:
66+
`AH00558: apache2: Could not reliably determine the server's fully qualified domain name...`
67+
you can safely ignore it.
68+
69+
.. _docker-cli-automated-setup-compose:
70+
71+
Define setup parameters in docker-compose.yml
72+
=============================================
73+
74+
To automate setup, you must provide all required parameters via environment
75+
variables. Add these to the `web` service in your `docker-compose.yml`:
76+
77+
.. literalinclude:: _codesnippets/_docker-compose.yml
78+
:language: yaml
79+
:caption: docker-compose.yml (excerpt)
80+
81+
.. warning::
82+
83+
If you previously ran this setup, you need to remove existing files and
84+
volumes before rebuilding to trigger setup again:
85+
86+
.. code-block:: bash
87+
88+
docker compose down --volumes
89+
rm -rf typo3conf/* typo3temp/* fileadmin/*
90+
91+
Then rebuild and start the containers:
92+
93+
.. code-block:: bash
94+
95+
docker compose build --no-cache
96+
docker compose up -d
97+
98+
.. _docker-cli-automated-setup-verify:
99+
100+
Verify that TYPO3 setup ran successfully
101+
========================================
102+
103+
Check the logs to confirm that the setup script executed on startup:
104+
105+
.. code-block:: bash
106+
107+
docker logs -f compose-demo-typo3
108+
109+
Expected output includes:
110+
111+
.. code-block:: text
112+
113+
[INFO] No settings.php found, running 'typo3 setup'...
114+
✓ Congratulations - TYPO3 Setup is done.
115+
116+
If the `settings.php` file is already present, you’ll instead see:
117+
118+
.. code-block:: text
119+
120+
[INFO] settings.php found, skipping setup.
121+
122+
.. _docker-cli-automated-setup-login:
123+
124+
Log in to the TYPO3 backend
125+
===========================
126+
127+
After the container is running and TYPO3 has been initialized, you can open the
128+
TYPO3 backend in your browser:
129+
130+
.. code-block:: text
131+
132+
http://localhost:8080/typo3/
133+
134+
Log in using the credentials you provided in `docker-compose.yml`, for example:
135+
136+
.. code-block:: text
137+
138+
Username: j.doe
139+
Password: Password.1
140+
141+
You should now see the TYPO3 backend dashboard and can start working on your site.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM martinhelmich/typo3:13.4
2+
3+
USER root
4+
5+
# Install Node.js and gosu (for user switching)
6+
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
7+
apt-get install -y nodejs gosu
8+
9+
# Copy the startup script into place
10+
COPY ./startup.sh /usr/local/bin/startup.sh
11+
RUN chmod +x /usr/local/bin/startup.sh
12+
13+
# Let the startup script run as entrypoint (it switches users internally)
14+
ENTRYPOINT ["/usr/local/bin/startup.sh"]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
version: '3.9'
2+
3+
services:
4+
db:
5+
image: mariadb:10.6
6+
container_name: compose-demo-typo3db
7+
environment:
8+
MYSQL_ROOT_PASSWORD: root
9+
MYSQL_DATABASE: db
10+
MYSQL_USER: db
11+
MYSQL_PASSWORD: db
12+
volumes:
13+
- db_data:/var/lib/mysql
14+
15+
web:
16+
build: .
17+
container_name: compose-demo-typo3
18+
ports:
19+
- "8080:80"
20+
depends_on:
21+
- db
22+
volumes:
23+
- ./fileadmin:/var/www/html/fileadmin
24+
- ./typo3conf:/var/www/html/typo3conf
25+
- ./typo3temp:/var/www/html/typo3temp
26+
environment:
27+
TYPO3_CONTEXT: Development
28+
TYPO3_DB_DRIVER: mysqli
29+
TYPO3_DB_USERNAME: db
30+
TYPO3_DB_PASSWORD: db
31+
TYPO3_DB_PORT: 3306
32+
TYPO3_DB_HOST: db
33+
TYPO3_DB_DBNAME: db
34+
TYPO3_SETUP_ADMIN_EMAIL: [email protected]
35+
TYPO3_SETUP_ADMIN_USERNAME: j.doe
36+
TYPO3_SETUP_ADMIN_PASSWORD: Password.1
37+
TYPO3_PROJECT_NAME: TYPO3-Dev
38+
39+
volumes:
40+
db_data:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
echo "[INFO] Running custom startup script..."
3+
4+
cd /var/www/html
5+
6+
if [ ! -f typo3conf/system/settings.php ]; then
7+
echo "[INFO] No settings.php found, running 'typo3 setup'..."
8+
gosu www-data ./typo3/sysext/core/bin/typo3 setup --no-interaction --force --server-type=apache || true
9+
else
10+
echo "[INFO] settings.php found, skipping setup."
11+
fi
12+
13+
exec apache2-foreground

0 commit comments

Comments
 (0)