Simply Explain The Concept of Docker

Simply Explain The Concept of Docker

We are starting after part one.

The part one article link is here: https://www.dhirubhai.net/pulse/simply-explain-concept-docker-md-shah-jalal-dc6me

Okay, Let's start with the technical part of Docker. ??

Prerequisites:

  1. Docker installed on your machine.
  2. Virtualization Enable
  3. Minimum RAM 4 GB
  4. Hyper-v Enable

Step 1: ?Create a project directory

Create a directory to store your project files. For example, you can create a directory named “my-app”.

mkdir my-app        
cd my-app        

Step 2: Create the app.js file

Create a file named app.js and say your code is:

console.log("Hello Docker");        

Step 3: Create a Dockerfile

A Dockerfile is a text file that contains instructions for building a Docker image. Create a file named Dockerfile and add the following content:

FROM node:16        
WORKDIR /app        
COPY package.json .        
RUN npm install        
COPY . .        
EXPOSE 3000        
CMD ["node", "app.js"]        

Step 4: Build the Docker image

Build the Docker image using the following command:

docker build -t my-app .        

This command will build the Docker image and tag (-t) it with the name my-app-image.

Step 5: Run the Docker Counter

Run the Docker container using the following command:

docker run my-app        

Another command:

To see images:

docker images        

or,

docker image ls        

To stop the running container:

docker stop my-app-container        

To remove the container:

docker rm my-app-container        

To remove the image:

docker rmi my-app-image        

After that, We have to push the Docker image on DockerHub to share with others.

We will need to have a DockerHub account and then log in using the command?

docker login        

  1. Create DockerHub Repo: Create a repository on Docker Hub for your image. You can do this by going to Docker Hub and clicking on the "Create Repository" button.
  2. Tag your Docker image: Tag your Docker image with the username and repository name you created in step 1. For example, if your Docker Hub username is myusername and your repository name is my-image, you would tag your image with the following command: docker tag my-image myusername/my-image
  3. Push Docker Image: docker push myusername/my-image

And then click on public view and now you can share the repo with others.

To run and pull from the DockerHub Repo:

docker pull myusername/my-image        
docker run myusername/my-image        

Docker provides a consistent, portable, isolated, lightweight, scalable, agile, and simple way to develop, deploy, and manage applications to focus on building great software without worrying about the underlying infrastructure.

要查看或添加评论,请登录

Md Shah Jalal的更多文章

社区洞察

其他会员也浏览了