A Basic Docker Implementation
Andrew Ciccarelli
Providing end-to-end digital transformation in the cloud - including AI
Introduction
This article is part 2 of a 3-Part Introduction to Docker and Kubernetes. This article focuses specifically on a basic Docker implementation. The supporting Demo App is available here.
Dockerfile
A Docker implementation revolves around the implementation of a Dockerfile configured in the root folder of an application. A Dockerfile is a simple configuration file named “Dockerfile” with no file type extension. It contains a series of instructions on how to build a Docker image. It automates the process of creating Docker images, ensuring consistency and repeatability.
Next Steps
In order to run the Docker sample app, you'll need to install Docker on your machine:
Then Open Docker Desktop from Programs and Sign In.
Build the Docker Image
Run the following command from the app root directory to build the Docker image:
docker build -t intro-to-docker-and-kubernetes .
Make sure to let the build process finish completely before proceeding to the next step. The build process will display a FINISHED status to the terminal like this when it has finished:
[+] Building 5.4s (9/9) FINISHED
Run the Docker Container
Run the following command to run the Docker container from the built image:
docker run -p 3000:3000 intro-to-docker-and-kubernetes
This command runs the container from the intro-to-docker-and-kubernetes image, mapping port 3000 of the container to port 3000 on your host machine.
Expected Output
After running the Docker container, you can access the application by navigating to https://localhost:3000 in your web browser. You should see the following output:
Hello, World!
This confirms that your Node.js application is running inside a Docker container.
Conclusion
This article provided a basic introduction to Docker and demonstrated how to configure and host a simple Node.js application within a Docker container. By following the steps outlined, you should now have a working Docker container running a "Hello, World!" Node.js app. Happy Containerizing!