To create a Docker image, you typically use a Dockerfile, which is a text file that contains instructions on how to build the image. Here are the steps to create a Docker image:
-
Create a Dockerfile: Open a terminal and create a new file named
Dockerfile(without any file extension).nano Dockerfileor
vim Dockerfile -
Define the Base Image: Start your
Dockerfileby specifying a base image using theFROMinstruction. For example:FROM ubuntu:latest -
Add Instructions: Add other instructions to install dependencies, copy files, and set up the environment. For example:
RUN apt-get update && apt-get install -y python3 COPY . /app WORKDIR /app CMD ["python3", "app.py"] -
Build the Image: Once your
Dockerfileis ready, run the following command in the terminal to build the image. Replacemyappwith your desired image name.docker build -t myapp . -
Verify the Image: After the build process completes, you can verify that your image has been created by running:
docker images
This will list all available Docker images, including the one you just created.
