How to Create Simple Docker Container Environment?
Before creating our first docker container let’s see what is docker.
- Docker is an open-source platform and set of tools that enables you to automate the deployment, scaling, and management of applications using containerization. It provides a way to package an application and its dependencies into a standardized unit called a container, which can run consistently across different environments.
- A Docker container is a lightweight and isolated runtime environment that allows you to package an application and its dependencies into a standardized unit called a container. A container is a standalone executable package that includes everything needed to run the application, such as code, runtime, system tools, libraries, and settings.
- A Docker image is a lightweight, standalone, and executable package that contains everything needed to run an application, including the code, runtime, libraries, environment variables, and system tools. It serves as a template for creating Docker containers.
Now we have learned about some basic terms related to docker now lets move towards how to create a simple docker environment.
Followings are the steps to create a docker container
step 1: Download and install docker desktop from here.
step 2: Open your vs code editor and create two files named as Dockerfile and index.js
step 3: Write following code inside your Dockerfile
A Dockerfile is a text file that contains a set of instructions used to build a Docker image. It serves as a recipe or blueprint for automating the creation of a Docker image, specifying the necessary steps to prepare the image’s environment.
FROM node:alpine
COPY . /tut
CMD node /tut/index.js
- FROM node:alpine
This line specifies the base image for the Docker image you’re creating. It uses the node:alpine image, which is a lightweight version of the Node.js runtime based on the Alpine Linux distribution. This base image already has Node.js pre-installed. - COPY . /tut
This line copies the contents of the current directory (denoted by . ) into the Docker image.
tut is name of my current directory - CMD node /tut/index.js
This line sets the default command to be executed when a container is created from the image.
step 4: write following code on your index.html
console.log("namaste duniya")
console.log("my first docker container")
step5: Open you Docker Desktop
step6: Open terminal in your vs code and run following commands
docker --version
- this will show the current version of docker installed in your machine.
docker build -t tut .
- This command is used to build a Docker image using the Dockerfile present in the current directory (
.
denotes the current directory).
tut is name of my current directory
docker images
- The docker images command is used to list the Docker images that are currently present on your system
We have successfully created our docker environment 😁
Open your Docker Desktop to see your image
click on play ▷ button to run new Docker Environment
Thus we have successfully created Simple Docker Conatiner 😍