How to run the container with the help of Docker .

How to run the container with the help of Docker .

Publish Date: May 14
0 0

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 .

Enter fullscreen mode Exit fullscreen mode

🟢 Step 3: Verify Image is Built

docker images
Enter fullscreen mode Exit fullscreen mode

🟢 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

🟢 Step 5: Check Running Containers

docker ps
Enter fullscreen mode Exit fullscreen mode

🟢 Step 6: Access Application in Browser

Open: http://localhost:5000
(Depends on your app's port)
Enter fullscreen mode Exit fullscreen mode

✅ Push Docker Image to Docker Hub

🟢 Step 8: Login to Docker Hub

docker login
Enter fullscreen mode Exit fullscreen mode

🟢 Step 9: Push Image to Docker Hub ( make sure you add tag (v1))

docker push iamnk00/python-sample-app-demo:v1
Enter fullscreen mode Exit fullscreen mode

✅ Stopping & Cleaning Up

docker stop my-python-app
Enter fullscreen mode Exit fullscreen mode

🟢 Remove Container

docker rm my-python-app
Enter fullscreen mode Exit fullscreen mode

🟢 Remove Image (Optional)

docker rmi iamnk007/python-sample-app-demo:v1
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment