This assumes you have created a Sails app on docker using the docker run command.
Let's say you have installed an app named foo-app, and the files for the app reside at /usr/local/apps/foo-app on your Docker server. Move into the dirctory.
cd /usr/local/apps/foo-app
If you want to store logs in a file in the container, such as to /var/logs/foo.log, update the /usr/local/apps/foo-app/config/log.js file on the Docker system to use the Winston logger.
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 --volume option is used to define the base directory on the Docker server (/usr/local/app) that will be mounted to a directory in the container (/foo-app).
- The --workdir option is used to define the relative directory on the Docker server (/foo-app) where the app will be created. The combination of the volume base directory (/usr/local/app) and relative work directory (/foo-app) will define the absolute directory on the Docker server where files will be written (/usr/local/app/foo-app).
- The --publish option is used to configure the Docker server to listen on port 8080 and the container to listen on port 1337.
- The --name option is used to name the container foo-app.
- The sails:latest image is used
- The sails lift & command is used to start the app. Or, the sails inspect command could be used to start the app in inspect mode. By default, events will be logged at log level INFO. The --silly flag can be used to log events at log level silly (very verbose).
docker run --volume /usr/local/apps:/foo-app --workdir /foo-app --publish 8080:1337 --name foo-app sails:latest sails lift --silly &
If the app is successfully started, something like this should be returned. Notice the Sails service in the container is using port 1337.
info: Starting app...
info: Initializing project hook... (`api/hooks/custom/`)
info: Initializing `apianalytics` hook... (requests to monitored routes will be logged!)
info: ·• Auto-migrating... (alter)
info: Hold tight, this could take a moment.
info: ✓ Auto-migration complete.
debug: Running v0 bootstrap script... (looks like this is the first time the bootstrap has run on this computer)
info:
info: .-..-.
info:
info: Sails <| .-..-.
info: v1.4.3 |\
info: /|.\
info: / || \
info: ,' |' \
info: .-'.-==|/_--'
info: `--'-------'
info: __---___--___---___--___---___--___
info: ____---___--___---___--___---___--___-__
info:
info: Server lifted in `/opt/foo-app`
info: To shut down Sails, press <CTRL> + C at any time.
info: Read more at https://sailsjs.com/support.
debug: -------------------------------------------------------
debug: :: Wed Jul 21 2021 23:02:10 GMT-0500 (Central Daylight Time)
debug: Environment : development
debug: Port : 1337
debug: -------------------------------------------------------
Since the Docker server is listening on port 8080, you will navigate to http://<Docker server ip address or hostname>:8080 and the following should be displayed.
AVOID TROUBLE
If not found is returned, SELinux on your Docker server may be set to enforcing. One option is to update SELinux to permissive or disabled.
The docker stop command can be used to stop the foo-app container.
docker stop foo-app
Did you find this article helpful?
If so, consider buying me a coffee over at