Create a Docker File and using Docker file Build Images
A Dockerfile is a text file that contains all the commands a user could call on the command line to assemble an image. This Dockerfile example sets up a lightweight Python application container. It performs several key actions:
Uses the
python:3.8-slim
image as a base.Sets the working directory inside the container to
/app
.Copies the current directory's contents into the container at
/app
.Installs dependencies listed in
requirements.txt
.Makes port 80 available to the container's external network.
Sets an environment variable
NAME
with the valueWorld
.Specifies that the container runs
app.py
with Python when it launches.
Performing Tasks with Docker in a New Folder
To streamline your Docker workflows, follow these steps to create a folder where you can perform all related tasks:
Create a New Folder: Open your terminal and use the command
mkdir your-folder-name
to create a new folder where you will carry out your Docker tasks.Navigate to Your New Folder: Change your current directory to the newly created folder by entering
cd your-folder-name
.Initialize Your Docker Project: Inside the folder, you can now perform all Docker-related tasks, such as initializing Docker projects, creating Docker files, and managing Docker containers and images.
By organizing your Docker tasks within a specific folder, you maintain a clean and efficient workflow.
mkdir docker_config
vi Dockerfile
This Dockerfile provides a clear, reproducible method for building a containerized Python application.
This command will build your Docker container based on the instructions in the Docker file you created. Make sure you run this command within the docker_config
directory where your Dockerfile is located. The -t
flag tags your image my_python_app
for easy reference.
To verify that your Docker image has been successfully built, use the docker images
command, which will list all Docker images on your system, including your newly created my_python_app
image. This allows you to confirm that your image is ready for use.
docker images
Manage Images Commands
To remove the images
docker rmi image_name/imgae_id
Lists images
docker image ls
Tags an image
docker tag image_name/image_id tag_name
Last updated