Morph allows you to customize the runtime environment on Morph Cloud by editing the Dockerfile in your project.

Default Dockerfile Structure

The Dockerfile generated by the morph new command is structured as follows:

The reserved word MORPH_TASK_ROOT is a required environment variable for pip install to function correctly. Unless you have a specific reason, do not modify it.

# Base image for Morph Cloud
FROM public.ecr.aws/i1l4z0u0/morph-cloud:python3.9

# Set working directory
WORKDIR /var/task

# Install Python dependencies with poetry
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt --target "${MORPH_TASK_ROOT}"

# Copy source code and dependencies
COPY .morph/frontend/dist /var/task/.morph/frontend/dist
COPY .morph/core /var/task/core
COPY .morph/meta.json .morph/
COPY morph_project.yml .
COPY src ./src

# Command to run the Lambda function
CMD ["core.morph.api.app.handler"]

Adding Packages

You can add any OS-level packages you need by updating your project’s Dockerfile. Morph Cloud base images are built on Amazon Linux. For Python 3.11 and earlier, package installation can be done using the yum command, while Python 3.12 and later images are based on Amazon Linux 2023 and use microdnf.

For example, to install the curl package using yum:

To reduce the final image size, we recommend running yum clean all (or microdnf clean all on newer images) after installing packages to remove unnecessary files.

# Base image for Morph Cloud
FROM public.ecr.aws/i1l4z0u0/morph-cloud:python3.9

# Set working directory
WORKDIR /var/task

# Install OS-level dependencies
RUN yum update -y && yum install -y \
    curl \
    && yum clean all

-- truncated --

For Python 3.12 or newer images, you would use microdnf instead:

# Base image for Morph Cloud
FROM public.ecr.aws/i1l4z0u0/morph-cloud:python3.12

# Set working directory
WORKDIR /var/task

# Install OS-level dependencies
RUN microdnf install \
    curl \
    && microdnf clean all

-- truncated --

Changing the Python Version

When you create a project with the morph new command, you can choose from Python 3.9, 3.10, 3.11, or 3.12.

The version you select is reflected in the automatically generated configuration files so that the deployed application uses the same Python version.

morph new my_project

# Follow the interactive prompt to choose a Python version

The chosen Python version is also reflected in the project’s configuration files (like the Dockerfile), which you can further customize as needed.

Changing the Python Version After Deployment

If you need to change the Python version for your deployed environment later, update the base image tag in your project’s Dockerfile and redeploy.

Example: Using the Python 3.12 image

FROM public.ecr.aws/i1l4z0u0/morph-cloud:python3.12

-- truncated --

In this way, you can switch from python3.9 to any other version supported by Morph.