|
| 1 | +--- |
| 2 | +title: Dockerfile |
| 3 | +description: Learn about the available Docker images you can use as a base for your Apify Actors. Choose the right base image based on your Actor's requirements and the programming language you're using. |
| 4 | +slug: /actors/development/actor-definition/dockerfile |
| 5 | +sidebar_position: 4 |
| 6 | +--- |
| 7 | + |
| 8 | +**Learn about the available Docker images you can use as a base for your Apify Actors. Choose the right base image based on your Actor's requirements and the programming language you're using.** |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +When developing an [Actor](/sources/platform/actors/index.mdx) on the Apify platform, you can choose from a variety of pre-built Docker iamges to serve as the base for your Actor. These base images come with pre-installed dependencies and tools, making it easier to set up your development envrionment and ensuring consistent behavior across different environments. |
| 13 | + |
| 14 | +## Base Docker images |
| 15 | + |
| 16 | +Apify provides several Docker images that can serve as base images for Actors. All images come in two versions: |
| 17 | + |
| 18 | +- `latest` - This version represents the stable and production-ready release of the base image. |
| 19 | +- `beta` - This version is intended for testing new features. Use at your own risk. |
| 20 | + |
| 21 | +:::note Pre-cached Docker images |
| 22 | + |
| 23 | +All Apify Docker images are pre-cached on Apify servers to speed up Actor builds and runs. The source code for generating these images is available in the [apify-actor-docker](https://github.com/apify/apify-actor-docker) repository. |
| 24 | + |
| 25 | +::: |
| 26 | + |
| 27 | +### Node.js base images |
| 28 | + |
| 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. |
| 30 | + |
| 31 | +| Image | Description | |
| 32 | +| ----- | ----------- | |
| 33 | +| [`actor-node`](https://hub.docker.com/r/apify/actor-node/) | Slim Alpine Linux image with only essential tools. Does not include headless browsers. | |
| 34 | +| [`actor-node-puppeteer-chrome`](https://hub.docker.com/r/apify/actor-node-puppeteer-chrome/) | Debian image with Chromium, Google Chrome, and the [`puppeteer`](https://github.com/puppeteer/puppeteer) library. | |
| 35 | +| [`actor-node-playwright-chrome`](https://hub.docker.com/r/apify/actor-node-playwright-chrome/) | Debian image with Chromium, Google Chrome, and the [`playwright`](https://github.com/microsoft/playwright) library. | |
| 36 | +| [`actor-node-playwright-firefox`](https://hub.docker.com/r/apify/actor-node-playwright-firefox/) | Debian image with Firefox and the [`playwright`](https://github.com/microsoft/playwright) library . | |
| 37 | +| [`actor-node-playwright-webkit`](https://hub.docker.com/r/apify/actor-node-playwright-webkit/) | Ubuntu image with WebKit and the [`playwright`](https://github.com/microsoft/playwright) library. | |
| 38 | +| [`actor-node-playwright`](https://hub.docker.com/r/apify/actor-node-playwright/) | Ubuntu image with [`playwright`](https://github.com/microsoft/playwright) and all its browsers (Chromium, Google Chrome, Firefox, WebKit). | |
| 39 | + |
| 40 | +See the [Docker image guide](/sdk/js/docs/guides/docker-images) for more details. |
| 41 | + |
| 42 | +### Python base images |
| 43 | + |
| 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. |
| 45 | + |
| 46 | +| Image | Description | |
| 47 | +| ----- | ----------- | |
| 48 | +| [`actor-python`](https://hub.docker.com/r/apify/actor-python) | Slim Debian image with only the Apify SDK for Python. Does not include headless browsers. | |
| 49 | +| [`actor-python-playwright`](https://hub.docker.com/r/apify/actor-python-playwright) | Debian image with [`playwright`](https://github.com/microsoft/playwright) and all its browsers. | |
| 50 | +| [`actor-python-selenium`](https://hub.docker.com/r/apify/actor-python-selenium) | Debian image with [`selenium`](https://github.com/seleniumhq/selenium), Google Chrome, and [ChromeDriver](https://chromedriver.chromium.org/). | |
| 51 | + |
| 52 | +## Custom Dockerfile |
| 53 | + |
| 54 | +Apify uses Docker to build and run Actors. If you create an Actor from a template, it already contains an optimized `Dockerfile` for the given use case. |
| 55 | + |
| 56 | +To use a custom `Dockerfile`, you can either: |
| 57 | + |
| 58 | +- Reference it from the `dockerfile` field in `.actor/actor.json`, |
| 59 | +- Store it in `.actor/Dockerfile` or `Dockerfile` in the root directory (searched in this order of preference). |
| 60 | + |
| 61 | +If no `Dockerfile` is provided, the system uses the following default: |
| 62 | + |
| 63 | +```dockerfile |
| 64 | +FROM apify/actor-node:20 |
| 65 | + |
| 66 | +COPY package*.json ./ |
| 67 | + |
| 68 | +RUN npm --quiet set progress=false \ |
| 69 | + && npm install --only=prod --no-optional \ |
| 70 | + && echo "Installed NPM packages:" \ |
| 71 | + && (npm list --only=prod --no-optional --all || true) \ |
| 72 | + && echo "Node.js version:" \ |
| 73 | + && node --version \ |
| 74 | + && echo "NPM version:" \ |
| 75 | + && npm --version |
| 76 | + |
| 77 | +COPY . ./ |
| 78 | +``` |
| 79 | + |
| 80 | +For more information about `Dockerfile` syntax and commands, see the [Dockerfile reference](https://docs.docker.com/engine/reference/builder/). |
| 81 | + |
| 82 | +:::note Custom base images |
| 83 | + |
| 84 | +While `apify/actor-node` is a base Docker image provided by Apify, you can use other Docker images as the base for your Actors. <br/> |
| 85 | +However, using the Apify images has some performance advantages, as they are pre-caches on Apify servers. |
| 86 | + |
| 87 | +::: |
| 88 | + |
| 89 | +By default, Apify base Docker images with the Apify SDK and Crawlee start your Node.js application the same way as `npm start`, i.e, by running the command specified in `package.json` under `scripts` - `start`. The default `package.json` is similar to: |
| 90 | + |
| 91 | +```json |
| 92 | +{ |
| 93 | + "description": "Anonymous Actor on the Apify platform", |
| 94 | + "version": "0.0.1", |
| 95 | + "license": "UNLICENSED", |
| 96 | + "main": "main.js", |
| 97 | + "scripts": { |
| 98 | + "start": "node main.js" |
| 99 | + }, |
| 100 | + "dependencies": { |
| 101 | + "apify": "^3.0.0", |
| 102 | + "crawlee": "^3.0.0" |
| 103 | + }, |
| 104 | + "repository": {} |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +This means the system expects the source code to be in `main.js` by default. If you want to override this behavior, ues a custom `package.json` and/or `Dockerfile`. |
0 commit comments