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.
Nitro Discontinued
Craft Nitro was discontinued on June 28, 2022. Read the official blog post titled Retiring Craft Nitro to learn more.
Assumptions
- Craft 3.6.x running in in Craft Nitro 2.0.8 in a local development environment. The instructions below may or may not work in earlier and/or later versions of Craft and/or Nitro 2.x.
- Craft Scripts 1.2.13, or later.
Instructions
From your Craft project’s root directory on your host machine, run:
nitro ssh --root
to SSH into project’s container as the root user.apk add bash
to install the Alpine Linux bash shell package.apk add rsync
to install the Alpine Linux rsync package.apk add openssh-client
to install the Alpine Linux OpenSSH client package.exit
to exit as root user.nitro ssh
to ssh into container.bash pull_assets.sh
, from yourscripts
directory to pull down assets from remote production/staging environment.bash db.sh
from within yourscripts
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.