Simply Explain The Concept of Docker
Md Shah Jalal
Helping Luxury Real Estate Agents Get High-End Clients with Stunning Websites, Advanced UX, Powerful Features, & 1:1 Consultancy??Results in 14 Days, Insha Allah! ?? DM Me Now!
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:
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
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.