Services

Run MySQL, PostgreSQL, Redis, Mailpit and S3 storage as local Anvil services, add Docker containers and servers elsewhere, pick their ports and connect your applications.

Anvil runs MySQL, PostgreSQL, Redis, Mailpit and S3 storage as services. Nothing runs until you add it. Each service has a kind, a name and a port, and you can add as many of each kind as you need. A Docker container or an external server can be a service too.

anvil service add mysql                      # a readable name such as mysql-swift-ember, usual port
anvil service add redis cache --port 6380    # a second Redis named "cache"
anvil service list

In the app: Services in the sidebar, then + (⌘N, or Ctrl+N on Windows and Linux, while Services is selected). Default names look like redis-swift-ember.

Services in the app: MySQL with its databases, the .env lines to connect and the apps that use it; Docker containers and an external server in the sidebar

Available services

ServiceUsual port
MySQL3306
PostgreSQL5432
Redis6379
Mailpit1025 (SMTP), web inbox on 8025
S3 storage: Versity S3 Gateway7070, web console on 7071
S3 storage: SILO9000, web console on 9001

MySQL, PostgreSQL and Redis offer several versions: list them with anvil service versions, pick one with --version. Redis is built from source the first time: on macOS it needs the Xcode command line tools, on Linux gcc and make, which the first MySQL also needs. On Windows, Redis is Garnet, which speaks Redis's protocol, in one version.

On macOS, MySQL needs 14, PostgreSQL 15 and Mailpit 13. On an older Mac, adding one is refused before anything downloads, e.g. "MySQL 8.4.11 needs macOS 14 or later; this Mac has 13.6."

Versions and data

A service keeps the version it was added with. Data folders don't survive a major upgrade, so run a new version as a new service alongside the old one.

Programs are downloaded on first use and shared in ~/.anvil/services/<kind>/<version>. Data lives in ~/.anvil/data/<name>, logs in ~/.anvil/log. anvil service uninstall <kind> <version> removes a program version no service uses.

Removing a service keeps its data unless you pass --delete-data. In the app, Remove Service… asks: Remove, Keep Data (the default) or Remove and Delete Data. Re-adding the same name finds your databases.

Ports

If the usual port is taken, Anvil suggests the next free one, never one of its own web or DNS ports. anvil service port <name> <port> changes it; omit the port to reset. --web <port> sets the Mailpit inbox or S3 console port.

Accounts

Services listen on 127.0.0.1 only.

  • MySQL starts with a root user without a password.
  • PostgreSQL starts with a postgres user and trust authentication.
  • S3 storage has one account: access key anvil, secret key anvil-secret.

Licenses

You accept each program's license once, before its first install (--accept-license in the CLI).

Starting and stopping

Enabled services start with Anvil (anvil service enable/disable <name>). Start and Stop in the app act now and also enable or disable the service. anvil service start/stop <name> do the same while the app is open.

A service's right-click menu has Start or Stop, Restart while it runs, and Rename… (a stopped service; its data and log move along). The Processes window has Restart too; the service's log icon opens its live log there.

Docker

Anvil runs an image for you, or adds a container you already have. It uses the Docker on this computer and doesn't install it.

anvil service add --docker mongo:7 --port 27017:27017 --env KEY=value
anvil service add --container my-db
  • An image's container is anvil-<name>, made at its first start, published on 127.0.0.1 only. --port is PORT:CONTAINER_PORT; --env repeats.
  • The image's data folders go into Docker volumes named after the container, so re-adding the same name finds them.
  • Anvil starts, stops and restarts the container. Removing an image's service deletes its container, and its volumes with --delete-data.
  • A container you added stays as it is: Anvil never creates or deletes it.
  • A crashed container says so.

External servers

A MySQL, PostgreSQL or Redis server elsewhere, or one on this computer that isn't Anvil's:

anvil service add --external db.lan:3306 --kind mysql --user app --password secret --database shop

--kind is mysql, postgres, redis or other. Anvil doesn't run it: its dot is green, and its page says Reachable, while it can be reached. The first three get Connect's .env lines and the database apps. Removing it only takes it out of Anvil.

S3 storage

Two kinds:

Both are downloaded from their GitHub release and checked against its published SHA-256 list.

anvil service add versitygw files
anvil service add silo objects

Each starts with one bucket, anvil. Every folder in ~/.anvil/data/<name> is a bucket. The Connect section shows the Laravel .env lines:

AWS_ACCESS_KEY_ID=anvil
AWS_SECRET_ACCESS_KEY=anvil-secret
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=anvil
AWS_ENDPOINT=http://127.0.0.1:7070
AWS_USE_PATH_STYLE_ENDPOINT=true

AWS_ENDPOINT uses the service's port (default 7070 for Versity S3 Gateway, 9000 for SILO). The console button opens the web console; sign in with the same keys.

Connecting applications

Link services to applications (anvil service link <name> myapp) and tag them (anvil service tag <name> queue). A link only lists the service on the app's Overview and Resources; it changes no .env.

Connect shows the service's .env lines to copy. Each linked app gets a button, e.g. Write to blog's .env…, that sets those keys in its .env after you confirm; its other lines stay. Running processes get them when they restart.

Anvil also reads each application's .env and identifies every database, cache and mail server it points at: an Anvil service, a Docker container or Compose service, another local program, or a remote host. anvil usage <site> shows the same.

What's inside

For a running service, anvil service databases <name> lists:

  • MySQL and PostgreSQL databases and their sizes
  • Redis keys and memory
  • Mailpit messages
  • S3 buckets and their sizes

anvil service create-db and drop-db manage databases. With the Database viewer on, Browse opens a MySQL or PostgreSQL service, or one of its databases, in Adminer, logged in.

The app can also flush Redis and delete all Mailpit messages. On macOS it opens a service in an installed database app: TablePlus, Sequel Ace, Postico 2, DBeaver, DataGrip, Beekeeper Studio, RedisInsight or Another Redis Desktop Manager.

On this page