Customize your Astro project Dockerfile
By default, the Astro project Dockerfile only includes a FROM
statement that specifies your Astro Runtime version. However, you can extend your Dockerfile to use a different distribution or run additional buildtime arguments. Use this document to learn which Dockerfile customizations are supported both locally and on Astro.
Prerequisites
Use an alternative Astro Runtime distribution
Starting with Astro Runtime 9, each version of Astro Runtime has a separate distribution for each currently supported Python version. Use an alternative Python distribution if any of your dependencies require a Python version other than the default Runtime Python version.
To use a specific Python distribution, update the first line in your Astro project Dockerfile
to reference the required distribution:
FROM quay.io/astronomer/astro-runtime:<runtime-version>-python-<python-version>
For example, to use Python 3.10 with Astro Runtime version 9.0.0, you update the first line of your Dockerfile to the following:
FROM quay.io/astronomer/astro-runtime:9.0.0-python-3.10
Run commands on build
To run additional commands as your Astro project is built into a Docker image, add them to your Dockerfile
as RUN
commands. These commands run as the last step in the image build process.
For example, if you want to run ls
when your image builds, your Dockerfile
would look like this:
FROM quay.io/astronomer/astro-runtime:12.6.0
RUN ls
This is supported both on Astro and in the context of local development.
Add a CA certificate to an Astro Runtime image
If you need your Astro Deployment to communicate securely with a remote service using a certificate signed by an untrusted or internal certificate authority (CA), you need to add the CA certificate to the trust store inside your Astro project's Docker image.
-
In your Astro project
Dockerfile
, add the CA certificate to the base Runtime image above the existingFROM quay.io/astronomer/astro-runtime:<runtime-version>-base
statement:USER root
COPY <internal-ca.crt> /usr/local/share/ca-certificates/<internal-ca.crt>/
RUN update-ca-certificates
USER astro
FROM quay.io/astronomer/astro-runtime:<runtime-version>-base
USER root
COPY <internal-ca.crt> /usr/local/share/ca-certificates/<internal-ca.crt>
RUN update-ca-certificates
COPY packages.txt .
ONBUILD RUN if [[ -s packages.txt ]]; then \
apt-get update && cat packages.txt | tr '\r\n' '\n' | sed -e 's/#.*//' | xargs apt-get install -y --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*; \
fi
COPY requirements.txt .
RUN pip install --no-cache-dir --root-user-action=ignore -r requirements.txt
USER astro
COPY . .infoWhen using a base image, make sure to install the system level and python packages.
-
(Optional) Add additional
COPY
statements before theRUN update-ca-certificates
stanza for each CA certificate your organization is using for external access. -
Restart your local environment or deploy to Astro. See Deploy code.