Docker Deployment
Follow these instructions to to deploy a Skulljs project with Docker.
Requirements
- Working project — check that your project works locally
- Node.js on local computer — latest LTS version or newer
- Skulljs-cli on local computer — the version you used to create the project or a newer version
- Docker and Docker Compose installed on the remote server — the latest LTS
- (Optional: HTTPS) An SSL Certificate
Deploy your app
Set up SSL certificate
(Optional) Set up SSL certificate for HTTPS
- Put your certificate key in sslcert/xxx.key.pem, you are only able to rename the xxx part.
- Put your certificate file in sslcert/xxx.cert.pem, you are only able to rename the xxx part.
Build the project
sk build
- Enter the name of the app
- Enter the ip address or the name of the remote server where you wish to deploy your application.We recommend to enter the name rather than the ip address to make sure you don’t encounter problems with certificates.
- Enter the port of the remote server where you wish to deploy your application.
- Select which hypertext transfer protocol do you would like to use.Selecting HTTPS requires you to make the optional step. This is recommended.
- Select DOCKER when the CLI prompts you to select a manager
Setup the folder on the remote server
- Create a folder with the name of your choice in your server. Ex: my-awesome-app
- Copy the dist folder in that folder
- Edit the database config in .env and docker-compose.yml
The database hostname in .env is the service name in docker compose. Ex: database_<project_name>.
- MYSQL_ROOT_USER=root
- MYSQL_ROOT_PASSWORD=
- MYSQL_USER=
- MYSQL_PASSWORD=
- MYSQL_DATABASE=
Use Docker
We use docker to manage and keep our application online 24/7.
Start an app
In the dist folder, use the following command.
npm run docker:up
Managing process
You can use the following commands to manage your processes.
npm run docker:build
npm run docker:up
npm run docker:down
npm run docker:logs
Initialize the database in the docker container
- Wait for the docker containers to boot upThis can take up to 5min, execute ’npm run docker:logs’ once this delay has passed.
- Init the databaseActions may vary depending on the ORM being used. Please see below for examples.
Ex: Prisma
# Enter docker container
docker compose exec <app_name> bash
# Classic
npx prisma db push
npx prisma db seed
or
# With migration
npx prisma migrate deploy
npx prisma db seed
# Exit docker container
exit
Go to the app
Well done ! Your app is now deployed and available at:
http(s)://[the name or the ip of the server]:[port of the server]
Troubleshooting
Permissions problem
Please manually create the folder used in Docker volumes and ensure that it has appropriate permissions.