View a markdown version of this page

Docker and Finch - AWS Amplify

Docker and Finch

aws amplifygen3 local run runs your local AWS Amplify backend in containers on your computer, with Docker or Finch. Docker is the default. To use Finch, set the containerRuntime key in amplify.local.json or the AWS_AMPLIFY_CONTAINER_RUNTIME environment variable.

Which runtime to choose

Use Docker when Docker Desktop is installed or you can install it. For more information about installing Docker, see Get Docker.

Use Finch when Docker Desktop isn’t an option on your computer. Your teammates can use Docker with the same project.

Requirements

To run the local backend, you need the following:

  • A running runtime – Start Docker, or start Finch with finch vm start, before you run aws amplifygen3 local run and the other local commands that use the local backend. aws amplifygen3 local init and aws amplifygen3 local backend add only write files, and they don’t use the runtime.

  • A network connection for the first local run – The command downloads the local backend image from Amazon ECR Public, without signing in. Later runs work offline for up to 7 days after the CLI last verified the image.

  • Finch on Linux – Finch runs as root. The finch command on your PATH must run sudo -E finch. A plain sudo drops the environment variables that the CLI passes to the containers, and the local backend stops as it starts.

Local backends that run at the same time share one Docker or Finch engine. When the engine is busy, every local command runs slower. To free the engine, run aws amplifygen3 local stop in each project that you aren’t using.

How the CLI picks a runtime

You choose the runtime with the AWS_AMPLIFY_CONTAINER_RUNTIME environment variable or the containerRuntime key in amplify.local.json. Each takes docker or finch.

When both are set, AWS_AMPLIFY_CONTAINER_RUNTIME takes precedence over containerRuntime.

aws amplifygen3 local run checks the runtime in two steps before it starts the local backend:

  1. The docker or finch command is on your PATH.

  2. The runtime’s info command succeeds. It fails when the Docker daemon or the Finch virtual machine is stopped.

If either check fails, the command stops with container_runtime_not_found. Install the runtime, or start it (finch vm start for Finch), and run the command again. The CLI doesn’t switch runtimes on its own. When the other runtime’s command is on your PATH, the error’s resolution names that runtime and the setting to switch to it.

Switch to Finch

To use Finch for every command in a project, add "containerRuntime": "finch" to amplify.local.json in the project folder. The file isn’t committed, so your teammates keep their own runtime.

To use Finch for one command, set AWS_AMPLIFY_CONTAINER_RUNTIME on the command line. Run the following commands to start Finch and the local backend:

finch vm start AWS_AMPLIFY_CONTAINER_RUNTIME=finch aws amplifygen3 local run

To go back to Docker, set the value to docker, or remove the key and the variable.

Docker and Finch keep separate containers and volumes. When you switch runtimes, local run starts a new local backend with an empty database and applies your migrations. The old backend and its data stay in the runtime that created them. To remove them, switch back to that runtime and run aws amplifygen3 local destroy.

The PostgreSQL client for the db commands

The aws amplifygen3 local db commands run psql inside the running local backend. You don’t install a client for them. For more information about these commands, see Local database.

The following commands work on a deployed environment and run psql: db query, db connect, db lint, db inspect, db report, backend seed and backend gen-types. db dump runs pg_dump. While Docker or Finch runs, each of these commands runs the client in a container from the local backend image. If the image isn’t on your computer, the command downloads it first and prints Pulling the local backend image…​. The first download is large. Later downloads reuse its layers.

Read files through standard input

The psql in the image can’t read or write files on your computer. db query and backend seed stop with exit status 252 when the SQL has a psql command that names a file, such as \copy to or from a file, \i, \ir, \w, or \o and \g with a file name. Pipe the file in instead. Run the following command to load a CSV file into a table:

aws amplifygen3 db query "\copy notes from stdin csv" --env preview < notes.csv

Replace notes with the name of your table and notes.csv with your file. To run the file commands as written, name your own psql with --psql.

Use your own client

On a computer without Docker or Finch, install a client and name it on each command. Without a runtime or a named client, these commands stop with Docker is not running or not installed. The deployed database commands run psql in a container. (exit status 253). db dump needs pg_dump 17 or later, and the other commands need psql 16 or later. PostgreSQL 17 or later has both. The CLI uses a client that you name even while Docker runs. It doesn’t use a psql that is only on your PATH.

Install the client with one of the following commands:

System Install command Path to name

macOS

brew install libpq

$(brew --prefix libpq)/bin/psql

Amazon Linux 2023

sudo dnf install postgresql17, or sudo dnf swap postgresql15 postgresql17 over an older version

The psql that the package installs

Debian or Ubuntu

postgresql-client-17, from the PostgreSQL apt repository

The psql that the package installs

Run the following command to name the client on one command:

aws amplifygen3 db query "select now()" --env preview --psql "$(brew --prefix libpq)/bin/psql"

For db dump, name pg_dump with --pg-dump. To name a client once for every command, set AWS_AMPLIFY_PSQL_BIN and AWS_AMPLIFY_PG_DUMP_BIN to the paths of psql and pg_dump.

Settings

Setting Where Values

AWS_AMPLIFY_CONTAINER_RUNTIME

Environment variable

docker (default) or finch

containerRuntime

amplify.local.json

docker (default) or finch

--psql, AWS_AMPLIFY_PSQL_BIN

Flag on a db command, or environment variable

Path to psql 16 or later

--pg-dump, AWS_AMPLIFY_PG_DUMP_BIN

Flag on db dump, or environment variable

Path to pg_dump 17 or later

Errors

Error Cause Fix

container_runtime_not_found, with Docker is not installed or not on PATH.

The runtime’s command isn’t on your PATH

Install Docker or Finch, then run the command again

container_runtime_not_found, with Docker is installed but not running: …​

The runtime’s info command failed, because the Docker daemon or the Finch virtual machine is stopped

Start Docker, or run finch vm start, then run the command again. Finch prints the same messages with its own name

unsupported_container_runtime

AWS_AMPLIFY_CONTAINER_RUNTIME or containerRuntime has a value other than docker or finch

Set it to docker or finch, or remove it

Docker is not running or not installed. The deployed database commands run psql in a container. (exit status 253)

A db command found no running Docker or Finch, and you didn’t name a client

Start Docker or Finch, or name a client with --psql

psql at <path> is version 15; need >= 16.

The client that you named is too old

Name psql 16 or later

Exit status 252 from db query or backend seed

The SQL has a psql command that names a file on your computer

Pipe the file through standard input, or name your own psql

network_create_failed

The runtime couldn’t create the local backend’s network. The message quotes the runtime’s error

Fix what the message names, then run aws amplifygen3 local run. When Docker has run out of address ranges, run docker network prune, or add default-address-pools to the Docker daemon’s configuration

The local backend stops as it starts, on Linux with Finch

The finch command on your PATH runs a plain sudo

Make it run sudo -E finch