|
| 1 | +--- |
| 2 | +title: Dockerfile user updates |
| 3 | +description: Learn what changes you need to do in your Actor Docker files with the new user changes |
| 4 | +slug: /actors/development/docker-user-changes |
| 5 | +--- |
| 6 | + |
| 7 | +**Learn what changes and issues you might encounter after some of our Docker images migrate to a privilege-less user** |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +:::danger A note about the warning |
| 12 | + |
| 13 | +The warning in the base Docker images will be removed near the end of the year! Make sure you update your Docker files until then so you don't forget! |
| 14 | + |
| 15 | +If you have issues or questions about it, feel free to open an issue on our [GitHub repository](https://github.com/apify/apify-actor-docker/issues/new) |
| 16 | + |
| 17 | +::: |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +This page is mostly dedicated for the users of the following Docker images: |
| 22 | + |
| 23 | +- `apify/actor-node` |
| 24 | +- `apify/actor-python` |
| 25 | +- `apify/actor-python-playwright` |
| 26 | +- `apify/actor-python-selenium` |
| 27 | + |
| 28 | +### What's changed? |
| 29 | + |
| 30 | +These images are moving from using the built-in **`root`** user and a usually random work directory (for example `/usr/src/app`) to consistent ones with our other Docker images. |
| 31 | + |
| 32 | +Specifically, the user is now **`myuser`**, and the working directory is **`/home/myuser`**. |
| 33 | + |
| 34 | +Now, you might ask yourself: why?. Our node Docker images that come with browsers do this in order to ensure the Actor runs in a more-secure environment, should there be any vulnerabilities in the dependencies. |
| 35 | + |
| 36 | +We want to ensure all our images follow this pattern. As such, after this Pull Request on [GitHub](https://github.com/apify/apify-actor-docker/pull/188), that will become the default for all our Docker images. |
| 37 | + |
| 38 | +### Common issues |
| 39 | + |
| 40 | +#### Crawlee images automatically installing `git` in Python images |
| 41 | + |
| 42 | +If you've built your Actor using [Crawlee](https://crawlee.dev/) templates, you might have the following line in your Dockerfile: |
| 43 | + |
| 44 | +```dockerfile |
| 45 | +RUN apt update && apt install -yq git && rm -rf /var/lib/apt/lists/* |
| 46 | +``` |
| 47 | + |
| 48 | +You can safely remove this line, as the `git` package is now installed in the base image. |
| 49 | + |
| 50 | +#### `uv` package manager fails to install dependencies |
| 51 | + |
| 52 | +If you've built your Actor using [Crawlee](https://crawlee.dev/) templates, or you hand-rolled your own Dockerfile, |
| 53 | +you might have the following line in your Dockerfile: |
| 54 | + |
| 55 | +```dockerfile |
| 56 | +ENV UV_PROJECT_ENVIRONMENT="/usr/local" |
| 57 | +``` |
| 58 | + |
| 59 | +As of the move to the new user, this variable will cause `uv` to throw an error due to permission errors. You can safely remove it! |
| 60 | +Alternatively, you can adjust it to point to the `/home/myuser` directory. |
| 61 | + |
| 62 | +#### How do I copy my files while also `chown`ing them to the new user? |
| 63 | + |
| 64 | +When using the `COPY` instruction to copy your files to the container, you should append the `--chown=myuser:myuser` flag to the command. |
| 65 | + |
| 66 | +Here's a few common example: |
| 67 | + |
| 68 | +```dockerfile |
| 69 | +COPY --chown=myuser:myuser requirements.txt ./ |
| 70 | + |
| 71 | +COPY --chown=myuser:myuser . ./ |
| 72 | +``` |
| 73 | + |
| 74 | +:::warning |
| 75 | + |
| 76 | +If your Dockerfile contains a `RUN` instruction similar to the following one, you should remove it: |
| 77 | + |
| 78 | +```dockerfile |
| 79 | +RUN chown -R myuser:myuser /home/myuser |
| 80 | +``` |
| 81 | + |
| 82 | +Instead, add the `chown` flag to the `COPY` instruction: |
| 83 | + |
| 84 | +```dockerfile |
| 85 | +COPY --chown=myuser:myuser . ./ |
| 86 | +``` |
| 87 | + |
| 88 | +Running `chown` across multiple files will needlessly slow down the build process. |
| 89 | + |
| 90 | +::: |
| 91 | + |
| 92 | +#### The template I used is trying to add an `apify` user |
| 93 | + |
| 94 | +If your Docker file has instructions similar to the following: |
| 95 | + |
| 96 | +```dockerfile |
| 97 | +# Create and run as a non-root user. |
| 98 | +RUN adduser -h /home/apify -D apify && \ |
| 99 | + chown -R apify:apify ./ |
| 100 | +USER apify |
| 101 | +``` |
| 102 | + |
| 103 | +You should remove it, as the new user is now **`myuser`**. Don't forget to update your `COPY` instructions to use the `chown` flag with the `myuser` user. |
| 104 | + |
| 105 | +```dockerfile |
| 106 | +COPY --chown=myuser:myuser . ./ |
| 107 | +``` |
| 108 | + |
| 109 | +#### How do I install dependencies that require root access via `apt` / `apk`? |
| 110 | + |
| 111 | +The good news is that the **`root`** user is still available in the Docker images. If you must run steps that require root access, here's an example of how you should do it: |
| 112 | + |
| 113 | +```dockerfile |
| 114 | +FROM apify/actor-node:24 |
| 115 | + |
| 116 | +# Switch to root temporarily to install dependencies |
| 117 | +USER root |
| 118 | + |
| 119 | +RUN apt update \ |
| 120 | + && apt install -y <dependencies here> |
| 121 | + |
| 122 | +# Switch back to the non-root user |
| 123 | +USER myuser |
| 124 | + |
| 125 | +# ... |
| 126 | +``` |
| 127 | + |
| 128 | +If your Actor *needs* to run as **`root`** for some reason, just add the `USER root` in your Dockerfile after the `FROM` instruction. But for a majority of Actors, this is not the case. |
0 commit comments