Member-only story
A Beginners’ Cheat Sheet for Docker
Get to know what is docker and how to use it

What is Docker?
Docker has gained popularity for multiple reasons, one of them is creating portable containers which are fast & easy to deploy. As mentioned on their website a container packages your code along with any other dependencies so that it can be deployed across multiple platforms reliably. These containers can be run locally on your Windows, Mac & Linux. Secondly, major cloud systems like AWS or Azure do support them out of the box. Lastly, it can be used on any hosting space where it can be installed and run.
Containers are the building blocks of docker. In this blog, we will go through various commands that will help us manipulate and create containers. As we go through each command you will have a better understanding of how docker works. So let’s stick through till the end.
Prerequisites
Getting Started
Execute the below command to verify docker installation:
docker --version
It will print the version installed. Now, we will create a very basic Node.js app to containerize.
Create a folder named yay-docker. Secondly, create two files named server.js and package.json as below:
package.json
:
{
"name": "yay-docker",
"dependencies": {
"express": "^4.17.1"
}
}
server.js
:
const server = require("express")();
server.listen(8080, async () => { });
server.get("/yay-docker", async (_, response) => {
console.log('Request Received for yay-docker');
response.json({ "yay": "docker" });
});
In order to create a container we first need to create a “Dockerfile” as below:
Dockerfile
:
# Download the slim version of node
FROM node:17-slim# Set the work directory to app folder.
# We will be copying our code here
WORKDIR /app#Copy the contents of our project in the app folder inside container
COPY . .