The following example will demonstrate how to create a Docker image using a Dockerfile.

1. Create a file called Dockerfile in the directory where you want to store your image.

2. Add the following code to the Dockerfile to define the base image and set the working directory:

FROM ubuntu:latest
WORKDIR /app

3. Add the code to install any necessary packages:

RUN apt-get update && apt-get install -y
python3
python3-pip

4. Add the code to copy the application code into the image:

COPY . /app

5. Add the code to run the application:

CMD [“python3”, “app.py”]

6. Run the following command to build the image:

docker build -t my-app .

7. Run the following command to run the image:

docker run -p 8080:8080 my-app

Leave a Reply

Your email address will not be published. Required fields are marked *