You can easily build images and deploy it into docker container through a script. The script automatically reads the name and version of your application, and creates an image.
Why? You created a new version of the output in your project. The following steps should be performed to place the output into docker container:
- Shutdown the previously running container.
- If it has the same container name, delete the container.
- Clean up the previously used image.
- Set the image name and tag to build a new image.
- Fill in the command to build and deploy the image.
This script is simple, but it is taking your place. If you need to start a project quickly, this simple script will make your container deployment easier.
- You should be able to use
git
command from here. - You should be able to use
node
command from here. - You should be able to use
docker
command from here.
Firstly, copy the run script run.sh and generate Dockerfile in your project to deploy (or you can use the existing Dockerfile example we provide).
If both files are ready, add the script below to your package.json:
"scripts": {
"...": "...",
"deploy": "./script/run.sh"
}
Now you can use this command to run the script:
$ yarn deploy
When run.sh
script is executed, the following processes are executed sequentially:
- Print your current branch
- Extract the name and version of your application
- Build a new image
- Terminate the previous container with the same name
- Export environment variables
- Run a new container
- Cleanup the legacy images (the images with older version)
- Cleanup the dangling images (including other images)
The most important part is to customize the run command that is appropriate for your project framework or configuration. Other processes can be used universally, but the run command must be modified to suit your project.
Therefore, you must re-write the run command, and can modify the run.sh script to omit some non-essential processes.
- Run NestJS in here.