Dockerizing Express Js App – Part 2
In the previous part, we discussed the basics of Docker and how to create a Dockerfile for an Express Js app. In this part, we will go one step further and dockerize the app by building and running a Docker image.
Building the Docker Image
To build the Docker image for our Express Js app, we need to run the following command in the root directory of the app:
docker build -t express-app .
This command tells Docker to build an image based on the instructions in the Dockerfile in the current directory and tag it as “express-app”.
Running the Docker Image
Once the Docker image is built, we can run it with the following command:
docker run -p 3000:3000 express-app
This command tells Docker to run a container based on the “express-app” image and map port 3000 on the host machine to port 3000 on the container.
Verifying the Docker Container
After running the Docker container, we can open a web browser and navigate to http://localhost:3000
to see our Express Js app running inside the container.
Conclusion
By following the steps outlined in this article, we have successfully dockerized our Express Js app. Docker provides a convenient way to package and run applications in a consistent environment, making it easier to deploy and scale our app. In the next part, we will explore how to deploy the Dockerized app to a cloud platform such as AWS or GCP.