1) Create the account on https://hub.docker.com/ so you can trace your docker container/images.
2) You will get the username which we required for running your container you have to configured it over the docker with username and password.
3) You also need the Dockerfile to run the containers so make sure you are in the same folder where this dockerfile is present .
4) Follow the below command step by step
๐ข Step 1: Write a Dockerfile
๐ข Step 2: Build Docker Image
docker build -t <your-dockerhub-username>/<image-name>:<tag> .
# Example:
docker build -t iamnk007p/python-sample-app-demo:v1 .
๐ข Step 3: Verify Image is Built
docker images
๐ข Step 4: Run Container from Image
docker run -d -p 5000:5000 --name my-python-app iamnk007/python-sample-app-demo:v1
# -d = detached mode
# -p = port mapping (host:container)
# --name = custom container name
or you can run below command as well just make sure you are mentioning port in dockerfile
docker run -it iamnk007/python-sample-app-demo
๐ข Step 5: Check Running Containers
docker ps
๐ข Step 6: Access Application in Browser
Open: http://localhost:5000
(Depends on your app's port)
โ Push Docker Image to Docker Hub
๐ข Step 8: Login to Docker Hub
docker login
๐ข Step 9: Push Image to Docker Hub ( make sure you add tag (v1))
docker push iamnk00/python-sample-app-demo:v1
โ
Stopping & Cleaning Up
docker stop my-python-app
๐ข Remove Container
docker rm my-python-app
๐ข Remove Image (Optional)
docker rmi iamnk007/python-sample-app-demo:v1
summary (Quick Recap Commands):
docker build -t <username>/<image>:<tag> .
docker run -d -p 5000:5000 --name <container-name> <username>/<image>:<tag>
docker ps
docker login
docker push <username>/<image>:<tag>
docker stop <container-name>
docker rm <container-name>
docker rmi <username>/<image>:<tag>
Top comments (0)