This assumes you have created a Sails image on Docker.
A Docker image contains the code used to create a Docker container. In this way, an image is like a template used to create a container. An image is kind of like a snapshot of a virtual machine.
And the docker images command should return something like this.
~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nodejs/sails latest fb60d5e3e7c8 About a minute ago 973MB
node latest 7528ad312b56 About a minute ago 944MB
The following command can be used to create a new Sails app named foo-app. Let's break down this command.
AVOID TROUBLE
By default, in the container, the app will be located at /<app name>, such as /foo-app in this example. The second field in --volume will need to point to /<app name>.
- The docker run command is used
- The --rm flag is used to remove the container after the Sails app has been created, as we do not need to keep the container that was used to create the Sails app.
- The --volume option is used to mount a directory on your Docker server (/usr/local/apps/foo-app) to a directory in the container (/foo-app).
- The sails:latest image is used
- The sails new command is used to create a new Sails app. When the Sails image, as long as the -g or --global flag was used, then the sails new command can be used from any directory, including the /foo-app directory. The echo 1 option is used to create a Sails web app. Or, echo 2 could be used to create an empty Sails app.
docker run --rm --volume /usr/local/apps/foo-app:/foo-app sails:latest /bin/bash -c "echo 1 | sails new foo-app"
The following should be displayed. Since "echo 1" was used, a Sails web app will be created.
Choose a template for your new Sails app:
1. Web App · Extensible project with auth, login, & password recovery
2. Empty · An empty Sails app, yours to configure
(type "?" for help, or <CTRL+C> to cancel)
? 1
info: Installing dependencies...
Press CTRL+C to cancel.
(to skip this step in the future, use --fast)
info: Created a new Sails app `foo-app`!
Since --volume mounted the /usr/local/apps/foo-app directory on the Docker server to /foo-app in the container, the /usr/local/apps/foo-app directory on the Docker server should now exist and contain the files that make up foo-app.
~]# ll /usr/local/apps
drwxr-xr-x 9 root root 4096 Jul 31 05:29 foo-app
You can now start the Sails app using the docker run command or docker-compose up.
Did you find this article helpful?
If so, consider buying me a coffee over at