Dockerize an application in less than 3 minutes
Everyone knows Docker. Docker is a set of tools that use OS-level virtualization to deliver software in packages called containers. If you have never tried Docker before, this guide is a perfect place to start. Follow these instructions and it will take less than 3 minutes to Dockerize your first application.
Step 1. Install Docker. Follow the instructions for your platform:
Step 2. Install Node.js. The application we will containerize is written on Node.js. Therefore, we need tooling that will allow us to test the application locally without a container first. However, of course, we can use an application that is written in any other language.
Step 3. Download the sample app. Open your terminal and run these commands:
powershell "Invoke-WebRequest -Outfile app.js -Uri https://raw.githubusercontent.com/vladimirmukhin/nodejs-hello/main/app.js"
Step 4. Launch the application locally
Step 5. Make sure the application responds on port 3000
or open this address in your browser
Step 6. Create a Docker file. Create a file that is called Dockerfile(without extension) and add the following lines inside
Use node as your base image:
copy app.js into your container:
COPY ./app.js .
On a container startup run the application:
CMD node app.js
To summarize, your Dockerfile should look like this:
Step 7. Build your image.
docker build -t nodejs-hello:latest .
Step 8. Run your container.
docker run -d -p 3000:3000 nodejs-hello:latest
Step 9. Validate your container. Make sure the application responds on port 3000. But this time, it is actually being served from the container:
or open this address in your browser.
Congratulations! You have created your first docker image and launched your first container. Let me know in the comments how much time did it take for you.
Apply for individual mentorship here: https://yourdevopsmentor.com/apply/
Connect with me on LinkedIn: https://www.linkedin.com/in/vladimir-mukhin-devops/
The success story of my client: https://yourdevopsmentor.com/blog/from-biologist-to-devops-engineer/