Skip to content

Commit 82a3c62

Browse files
vladfranguTC-MO
authored andcommitted
docs: upgrades for privilege-less Docker images (apify#1817)
Co-authored-by: Michał Olender <[email protected]>
1 parent 8692d93 commit 82a3c62

File tree

1 file changed

+111
-5
lines changed
  • sources/platform/actors/development/actor_definition

1 file changed

+111
-5
lines changed

sources/platform/actors/development/actor_definition/docker.md

Lines changed: 111 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ All Apify Docker images are pre-cached on Apify servers to speed up Actor builds
2626

2727
### Node.js base images
2828

29-
These images come with Node.js (versions `16`, `18`, `20`, or `22`) the [Apify SDK for JavaScript](/sdk/js), and [Crawlee](https://crawlee.dev/) preinstalled. The `latest` tag corresponds to the latest LTS version of Node.js.
29+
These images come with Node.js (versions `20`, `22`, or `24`) the [Apify SDK for JavaScript](/sdk/js), and [Crawlee](https://crawlee.dev/) preinstalled. The `latest` tag corresponds to the latest LTS version of Node.js.
3030

3131
| Image | Description |
3232
| ----- | ----------- |
@@ -41,7 +41,7 @@ See the [Docker image guide](/sdk/js/docs/guides/docker-images) for more details
4141

4242
### Python base images
4343

44-
These images come with Python (version `3.8`, `3.9`, `3.10`, `3.11`, or `3.12`) and the [Apify SDK for Python](/sdk/python) preinstalled. The `latest` tag corresponds to the latest Python 3 version supported by the Apify SDK.
44+
These images come with Python (version `3.9`, `3.10`, `3.11`, `3.12`, or `3.13`) and the [Apify SDK for Python](/sdk/python) preinstalled. The `latest` tag corresponds to the latest Python 3 version supported by the Apify SDK.
4545

4646
| Image | Description |
4747
| ----- | ----------- |
@@ -61,9 +61,9 @@ To use a custom `Dockerfile`, you can either:
6161
If no `Dockerfile` is provided, the system uses the following default:
6262

6363
```dockerfile
64-
FROM apify/actor-node:20
64+
FROM apify/actor-node:24
6565

66-
COPY package*.json ./
66+
COPY --chown=myuser:myuser package*.json ./
6767

6868
RUN npm --quiet set progress=false \
6969
&& npm install --only=prod --no-optional \
@@ -74,7 +74,7 @@ RUN npm --quiet set progress=false \
7474
&& echo "NPM version:" \
7575
&& npm --version
7676

77-
COPY . ./
77+
COPY --chown=myuser:myuser . ./
7878
```
7979

8080
For more information about `Dockerfile` syntax and commands, see the [Dockerfile reference](https://docs.docker.com/reference/dockerfile/).
@@ -112,3 +112,109 @@ This means the system expects the source code to be in `main.js` by default. If
112112
You can check out various optimization tips for Dockerfile in our [Performance](../performance.md) documentation.
113113

114114
:::
115+
116+
## Updating older Dockerfiles
117+
118+
All Apify base Docker images now use a non-root user to enhance security. This change requires updates to existing Actor `Dockerfile`s that use the `apify/actor-node`, `apify/actor-python`, `apify/actor-python-playwright`, or `apify/actor-python-selenium` images. This section provides guidance on resolving common issues that may arise during this migration.
119+
120+
If you encounter an issue that is not listed here, or need more guidance on how to update your Dockerfile, please [open an issue in the apify-actor-docker GitHub repository](https://github.com/apify/apify-actor-docker/issues/new).
121+
122+
:::danger Action required
123+
124+
As of **August 25, 2025** the base Docker images display a deprecation warning that links you here. This warning will be removed start of **February 2026**, so you should update your Dockerfiles to ensure forward compatibility.
125+
126+
:::
127+
128+
### User and working directory
129+
130+
To improve security, the affected images no longer run as the `root` user. Instead, they use a dedicated non-root user, `myuser`, and a consistent working directory at `/home/myuser`. This configuration is now the standard for all Apify base Docker images.
131+
132+
### Common issues
133+
134+
#### Crawlee templates automatically installing `git` in Python images
135+
136+
If you've built your Actor using a [Crawlee](https://crawlee.dev/) template, you might have the following line in your `Dockerfile`:
137+
138+
```dockerfile
139+
RUN apt update && apt install -yq git && rm -rf /var/lib/apt/lists/*
140+
```
141+
142+
You can safely remove this line, as the `git` package is now installed in the base image.
143+
144+
#### `uv` package manager fails to install dependencies
145+
146+
If you are using the `uv` package manager, you might have the following line in your `Dockerfile`:
147+
148+
```dockerfile
149+
ENV UV_PROJECT_ENVIRONMENT="/usr/local"
150+
```
151+
152+
With the move to a non-root user, this variable will cause `uv` to throw a permission error. You can safely remove this line, or, if you need it set to a custom path, adjust it to point to a location in the `/home/myuser` directory.
153+
154+
#### Copying files with the correct permissions
155+
156+
When using the `COPY` instruction to copy your files to the container, you should append the `--chown=myuser:myuser` flag to the command to ensure the `myuser` user owns the files.
157+
158+
Here are a few common examples:
159+
160+
```dockerfile
161+
COPY --chown=myuser:myuser requirements.txt ./
162+
163+
COPY --chown=myuser:myuser . ./
164+
```
165+
166+
:::warning
167+
168+
If your `Dockerfile` contains a `RUN` instruction similar to the following one, you should remove it:
169+
170+
```dockerfile
171+
RUN chown -R myuser:myuser /home/myuser
172+
```
173+
174+
Instead, add the `--chown` flag to the `COPY` instruction:
175+
176+
```dockerfile
177+
COPY --chown=myuser:myuser . ./
178+
```
179+
180+
Running `chown` across multiple files needlessly slows down the build process. Using the flag on `COPY` is much more efficient.
181+
182+
:::
183+
184+
#### An `apify` user is being added by a template
185+
186+
If your `Dockerfile` has instructions similar to the following, they were likely added by an older template:
187+
188+
```dockerfile
189+
# Create and run as a non-root user.
190+
RUN adduser -h /home/apify -D apify && \
191+
chown -R apify:apify ./
192+
USER apify
193+
```
194+
195+
You should remove these lines, as the new user is now `myuser`. Don't forget to update your `COPY` instructions to use the `--chown` flag with the `myuser` user.
196+
197+
```dockerfile
198+
COPY --chown=myuser:myuser . ./
199+
```
200+
201+
#### Installing dependencies that require root access
202+
203+
The `root` user is still available in the Docker images. If you must run steps that require root access (like installing system packages with `apt` or `apk`), you can temporarily switch to the `root` user.
204+
205+
```dockerfile
206+
FROM apify/actor-node:24
207+
208+
# Switch to root temporarily to install dependencies
209+
USER root
210+
211+
RUN apt update \
212+
&& apt install -y <dependencies here>
213+
214+
# Switch back to the non-root user
215+
USER myuser
216+
217+
# ... your other instructions
218+
```
219+
220+
If your Actor needs to run as `root` for a specific reason, you can add the `USER root` instruction after `FROM`. However, for a majority of Actors, this is not necessary.

0 commit comments

Comments
 (0)