I’m trying to run n8n via docker and my flow requires python and community lib. I tried to run several times and there was always error which is mainly about apk. Honestly, I’m low code person so it is mainly gemini code. But here is how my Dockerfile looks like
FROM n8nio/n8n:latest
USER root
RUN apk add --update --no-cache
python3
py3-pip
build-base
python3-dev
libffi-dev
libxml2-dev
libxslt-dev
RUN python3 -m venv /opt/venv
ENV PATH=“/opt/venv/bin:$PATH”
RUN pip install --no-cache-dir
pdfplumber
python-docx
openpyxl
pandas
USER node
And here is my yml file
services:
n8n:
build: .
container_name: n8n-mine
restart: always
ports:
“5678:5678”
environment:
N8N_SECURE_COOKIE=false
EXECUTIONS_DATA_PRUNE=true
EXECUTIONS_DATA_MAX_AGE=168
GENERIC_TIMEZONE=Asia/Bangkok
TZ=Asia/Bangkok
N8N_BLOCK_FS_READ_ACCESS=false
N8N_BLOCK_FS_WRITE_ACCESS=false
N8N_RESTRICT_FILE_ACCESS_TO=/files
volumes:
n8n_data:/home/node/.n8n
./files:/files
volumes:
n8n_data:
The error code is below
I will really appreciate any suggestions. Thanks!
To get Python available in your local n8n instance running via Docker, you typically extend the official n8n image and install Python inside it, then run that custom image locally.
1. Create a Dockerfile that adds Python
Create a file named Dockerfile in an empty folder:
FROM docker.n8n.io/n8nio/n8n:latest
# Install Python and pip in the Alpine-based n8n image
USER root
RUN apk add --no-cache python3 py3-pip
USER node
This follows the same pattern used in community solutions where Python is added to the n8n container via apk add python3 py3-pip on Alpine-based images. [Can’t set up Whisper; Hostinger + Python]
2. Build the custom image
From the same folder as the Dockerfile:
docker build -t n8n-python .
3. Run n8n with the new image on localhost
Use the usual n8n Docker run command, but reference your new image:
This is the same pattern the docs use to start n8n locally with Docker, just pointing to your custom image instead of the stock one. [Docker installation]
After this, Python will be available inside the n8n container (for example to use from Execute Command, or for tools that rely on a system Python).
This solution no longer works with docker 4.69 as of 4/20/2026. I’ve been trying to find a solution and it seems like i’m going to have to bake in an installation of APK first. The hardening has removed the apk manager completely from the image.
So at this time we are unable to edit the docker image and we are unable to build using the n8n git repo docker files as they end up not compiling and the ./compile folder is never found.
To try and install the apk manager
#CODE BLOCK
FROM docker.n8n.io/n8nio/n8n:latest AS base
# Restore apk manually
USER root
RUN ARCH=$(uname -m) && \
if [ "$ARCH" = "x86_64" ]; then ARCH="x86_64"; else ARCH="aarch64"; fi && \
wget -qO- "http://dl-cdn.alpinelinux.org/alpine/latest-stable/main/${ARCH}/" | \
grep -o 'href="apk-tools-static-[^\"]*\.apk"' | head -1 | cut -d'"' -f2 | \
xargs -I {} wget -q "http://dl-cdn.alpinelinux.org/alpine/latest-stable/main/${ARCH}/{}" && \
tar -xzf apk-tools-static-*.apk && \
./sbin/apk.static -X http://dl-cdn.alpinelinux.org/alpine/latest-stable/main \
-U --allow-untrusted add apk-tools && \
rm -rf sbin apk-tools-static-*.apk
# Install Python and pip in the Alpine-based n8n image
RUN apk add --no-cache python3 py3-pip
USER node