How I Use Craft Scripts in Craft CMS Running in Craft Nitro 2

Published

In this article, I explain how I use Craft Scripts in my Nitro 2 local development environment to pull down user-generated assets and the Craft database from a remote Craft CMS production environment.

Craft Nitro logo

Nitro Discontinued

Craft Nitro was discontinued on June 28, 2022. Read the official blog post titled Retiring Craft Nitro to learn more.

Assumptions

Instructions

From your Craft project’s root directory on your host machine, run:

  1. nitro ssh --root to SSH into project’s container as the root user.
  2. apk add bash to install the Alpine Linux bash shell package.
  3. apk add rsync to install the Alpine Linux rsync package.
  4. apk add openssh-client to install the Alpine Linux OpenSSH client package.
  5. exit to exit as root user.
  6. nitro ssh to ssh into container.
  7. bash pull_assets.sh, from your scripts directory to pull down assets from remote production/staging environment.
  8. bash db.sh from within your scripts directory to pull down the Craft database from remote production/staging environment.

System changes made as the root user are ephemeral, so you’ll need to repeat steps 1-4 every time Nitro recreates the site’s container after you run nitro apply, nitro xon|xoff, or nitro update.

That’s it! By following the steps above, I can pull down user-generated assets and the Craft database from a remote Craft CMS production/staging environment into my Nitro 2 local development environment.