How To Create A Docker Image On Docker Desktop: A Step-By-Step Guide
Step 1 : Start the Docker engine . On windows just start the Docker Desktop .
On Ubuntu start the docker service using the command:
sudo systemctl start docker
Step 2 : Create a html file . We are going to dockerize a html file here in the upcoming steps .
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>How to create docker image</title>
</head>
<body>
<H1>Hey geeks to create a docker image you have to write a Dockerfile and then build it using
docker command .
</H1>
</body>
</html>
Step 3 : Then create a text document having name Dockerfile in the same folder as the html file. Here in this Dockerfile, all the instructions and commands will be written to create a Docker image . In the Dockerfile specify the base image , working directory and port number on which the website is running .
FROM nginx:alpine
COPY index.html /usr/share/nginx/html
EXPOSE 80
Step 4 : Build a docker image . Here mention a name for the Docker image and also mention the path of Dockerfile .
docker build -t gfg-image .
Step 5 : After successful build you can check whether the image is present or not .
docker images | grep gfg-image
Step 6 : Then you can run the image and access it through localhost .
docker run -d -p 80:80 gfg-image
- Here -d indicates that container running in detached mode and -p indicates the port number through which you can access the website .
- Now access the website on http://localhost:80 .
How to Create Docker Image?
Docker is a powerful containerization tool that enables developers to package their applications and their dependencies into a single unit called Docker image. The Docker image offers seamless deployment, scalability, and portability. In this article, I will make sure that you understand what is docker and guide you through the steps to create a Docker image.
Table of Content
- What is Docker?
- What is Docker Image?
- Why Create Docker Images?
- How to Create Docker Image With Dockerfile: A Step-By-Step Guide
- How to Create A Base Image Using Scratch? A Step-By-Step Guide
- How to Create a Full Image Using tar?
- How to Optimize Your Docker Image Size?
- How to Host Your Docker Image?
- Examples of Docker Commands for Creating a Dockerfile
- Dockerfile vs Docker Image Vs Container
- Docker Image Commands
- Key Commands of Docker Image And Docker Container
- Examples of Docker Image UseCases
- How To Create A Docker Image On Docker Desktop: A Step-By-Step Guide
- How to Create a Docker Image from Docker Container? A Step-By-Step Guide
- Conclusion
- Create Docker Image – FAQs
Contact Us