You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sources/platform/actors/development/actor_definition/docker.md
+106Lines changed: 106 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -112,3 +112,109 @@ This means the system expects the source code to be in `main.js` by default. If
112
112
You can check out various optimization tips for Dockerfile in our [Performance](../performance.md) documentation.
113
113
114
114
:::
115
+
116
+
## Updating older Dockerfiles
117
+
118
+
Certain 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
+
:::danger Action required
121
+
122
+
The base Docker images display a deprecation warning. This warning will be removed in future versions, so you should update your Dockerfiles to ensure forward compatibility.
123
+
124
+
For further assistance, [open an issue in the apify-actor-docker GitHub repository](https://github.com/apify/apify-actor-docker/issues/new).
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`:
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 adjust it to point to 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