Skip to content

Commit 78e23b1

Browse files
authored
docs: Dockerfile doc improvements & rewrites (#1031)
Ensure style guide compliance add new versions provide cross-references to other part of documentation Add admonitions rewrites for readability and clarity
1 parent 5275e87 commit 78e23b1

File tree

7 files changed

+117
-108
lines changed

7 files changed

+117
-108
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Actor `name`, `version`, `buildTag`, and `environmentVariables` are currently on
6969
| `version` | Required | The version of the Actor, specified in the format `[Number].[Number]`, e.g., `0.1`, `0.3`, `1.0`, `1.3`, etc. |
7070
| `buildTag` | Optional | The tag name to be applied to a successful build of the Actor. If not specified, defaults to `latest`. Refer to the [builds](../builds_and_runs/builds.md) for more information. |
7171
| `environmentVariables` | Optional | A map of environment variables to be used during local development. These variables will also be applied to the Actor when deployed on the Apify platform. For more details, see the [environment variables](/cli/docs/vars) section of Apify CLI documentation. |
72-
| `dockerfile` | Optional | The path to the Dockerfile to be used for building the Actor on the platform. If not specified, the system will search for Dockerfiles in the `.actor/Dockerfile` and `Dockerfile` paths, in that order. Refer to the [Dockerfile](./dockerfile.md) section for more information. |
72+
| `dockerfile` | Optional | The path to the Dockerfile to be used for building the Actor on the platform. If not specified, the system will search for Dockerfiles in the `.actor/Dockerfile` and `Dockerfile` paths, in that order. Refer to the [Dockerfile](./docker.md) section for more information. |
7373
| `dockerContextDir` | Optional | The path to the directory to be used as the Docker context when building the Actor. The path is relative to the location of the `actor.json` file. This property is useful for monorepos containing multiple Actors. Refer to the [Actor monorepos](../deployment/source_types.md#actor-monorepos) section for more details. |
7474
| `readme` | Optional | The path to the README file to be used on the platform. If not specified, the system will look for README files in the `.actor/README.md` and `README.md` paths, in that order of preference. Check out [Apify Academy article on writing a quality README files](/academy/get-most-of-actors/actor-readme) guidance. |
7575
| `input` | Optional | You can embed your [input schema](./input_schema/index.md) object directly in `actor.json` under the `input` field. You can also provide a path to a custom input schema. If not provided, the input schema at `.actor/INPUT_SCHEMA.json` or `INPUT_SCHEMA.json` is used, in this order of preference. |
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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`.

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

Lines changed: 0 additions & 95 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Basically, Actors are programs packaged as [Docker images](https://hub.docker.co
1616
Actors have the following elements:
1717

1818
- The main **[actor.json](./actor_json.md)** file contains **metadata** such as the Actor name, description, author, version, and links pointing to the other definition files below.
19-
- **[Dockerfile](./dockerfile.md)** which specifies where is the Actor's source code, how to build it, and run it.
19+
- **[Dockerfile](./docker.md)** which specifies where is the Actor's source code, how to build it, and run it.
2020
- **Documentation** in the form of a **README.md** file.
2121
- **[Input](./input_schema/index.md)** and **[output schemas](./output_schema.md)** that describe what input the Actor requires and what results it produces.
2222
- Access to an out-of-box **[storage](../../../storage/index.md)** system for Actor data, results, and files.

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@ sidebar_position: 4
99

1010
---
1111

12-
The structure and placement of an Apify Actor's source code is defined by its [`Dockerfile`](./dockerfile.md). If you create the Actor from one of Apify's [templates](https://apify.com/templates), the source code by default is placed in the `/src`.
12+
The Apify Actor's source code placement is defined by its [Dockerfile](./docker.md). If you have created the Actor from one of Apify's [templates](https://apify.com/templates) then it's by convention placed in the `/src` directory.
1313

1414
You have the flexibility to choose any programming language, technologies, and dependencies (such as Chrome browser, Selenium, Cypress, or others) for your projects. The only requirement is to define a Dockerfile that builds the image for your Actor, including all dependencies and your source code.
1515

1616
## Example setup
1717

18-
To better understand how to structure your Actor's source code, let's take a look at an example for a JavaScript Actor.
19-
20-
### `Dockerfile`
21-
22-
Here's the complete `Dockerfile`
18+
Let's take a look at the example JavaScript Actor's source code. The following Dockerfile:
2319

2420
```dockerfile
2521
FROM apify/actor-node:20

0 commit comments

Comments
 (0)