How to build Docker image from Docker file
▪ Create a folder → to save all image files on it
▪ Add a Dockerfile → Note: Docker file should be without extension
▪ Type your image code at Dockerfile
▪ Add your app file (like app.py)→ needed files for the image
▪ Build the image → docker build
o Docker image build --tag <name of image > <location of docker file>
o Example : docker image build --tag ayaayman0/hellopy:dev
D:\BFCAI\docker\myimages\pythonimage
▪ Run the container → docker container run <name of image >
▪ How to Push Docker image to the hup
▪ # docker login
▪ # docker image push <name and tag of the image>
▪ Example: docker image push ayaayman0/hellopy:dev
▪ Making new volume and shared data on it
o docker volume create mysql_data
o docker run -d --name mysql1 -e MYSQL_ROOT_PASSWORD=pass123 -v
mysql_data:/var/lib/mysql mysql:8.0
o docker run -d --name mysql2 -e MYSQL_ROOT_PASSWORD=pass123 -v
mysql_data:/var/lib/mysql mysql:8.0
o docker exec -it mysql1 mysql -u root -p
1. FROM python:3.9-slim
o Start from an official Python image (version 3.9).
o The slim version means it’s smaller and lighter (fewer extra tools installed).
2. WORKDIR /app
o Create (if not already there) a folder /app inside the container.
o Make it the “working directory.”
o Any command after this runs inside /app.
3. COPY . /app
o Copy everything from your current project folder (where the Dockerfile is) on
your computer → into /app inside the container.
o This includes app.py (your program).
4. CMD ["python", "app.py"]
o When the container starts, run: python app.py