In this tutorial, I show you how to use a new open source project, Appsody, to create an application locally and then build and deploy that application to a Docker Hub so you can use it on any cloud or platform that supports Docker images. After completing this tutorial, you will understand how Appsody enables you to containerize a Node.js Express application without having to be an expert in container technology.
To complete the steps in this tutorial, you need to:
This tutorial uses a sample application you can find in this GitHub repo. The first step is to clone the project.
cd downloads
command. (Or any other directory in which you want to clone the project).git clone https://github.com/mahsankhaan/appsody.git
. To open the application in VS Code, follow these steps:
Now you should be able to see all the files in VS code.
Before initializing Appsody, let's review some key Appsody terms:
For more, check out the documentation.
Steps to initialize appsody:
Open Visual Studio Code. Use CTRL + Shift + ` to access terminal from your VS code and execute the following commands:
From the terminal, enter appsody list
to view all available Appsody stacks.
Review the list of stacks and find one that closely resembles your existing project.
The sample application in this tutorial is a Node.js Expres app, so we select that.
Run the appsody init nodejs-express none
command to initialize a template.
NOTE
We use "none” in the above command because we are initializing Appsody in an existing project. If you want to initialize from start, then use *appsody init nodejs-express simple
which creates a Node.js application template with Appsody.
When you initialize a source code project with Appsody, you get a local Appsody development container. Use the ‘appsody run’ command to start the development container in ‘run’ mode in the foreground. Appsody watches your local project directory for file changes and updates the application to reflect code changes as you develop.
localhost:3000
. 3000 is the default port to run a Node.js application.Make some changes to your code and check for updates. Here are some minor changes you can make:
After you finished creating your Appsody application on your local system, you can deploy it to a container platform. The following steps show you how to containerize it and upload it to Docker Hub. From there, you can easily deploy it to a suitable runtime infrastructure such as IBM Cloud.
app-deploy.yml
file in the left navigation.docker images
command to see your image on your local machine.You should see that a registry is created with the username/appsody. For instance, mine is ahsanoffical/appsody. You can use this registry to push and pull the images.
docker login
command. You should see the newly created image name is testing-appsody
.docker tag testing-appsody ahsanoffical/appsody:testing
.docker push ahsanoffical/appsody:testing
In the future, you can pull the image anywhere by using the docker pull ahsanoffical/appsody:testing
command.
In this tutorial, you learned how to integrate Appsody in VS Code to minimize the local development workload, containerize the application and upload to Docker Hub to prepare it for deployment to any cloud platform that supports Docker images.