top of page

Step 1 — Create project folder in VS Code

  1. Open VS Code

  2. Go to File → Open Folder

  3. Create/open a folder named:hello-docker-python

Step 2 — Create files

Inside VS Code, create these files:

📄 1. hello.py

print("Hello from Dockerized Python!")

📄 2. Dockerfile

FROM python:3.11-slim
WORKDIR /app
COPY hello.py .
CMD ["python", "hello.py"]

📄 3. .dockerignore

__pycache__
*.pyc
.git

📄 4. README.md

Simple Python Docker demo.

Run:
  docker build -t hello-python .
  docker run --rm hello-python

Step 3 — Test Docker locally (optional but recommended)

Open VS Code terminal:Ctrl + `

Run:

docker build -t hello-python .

Then run:

docker run --rm hello-python

Expected output:

Hello from Dockerized Python!

If you see this, Docker is correct.

Step 4 — Upload project to GitHub from VS Code

A) Create empty GitHub repo

  1. Go to GitHub → New Repository

  2. Name: hello-docker-python

  3. Do NOT add README

Copy your repository HTTPS URL, example:

B) Push your project from VS Code

In the VS Code terminal, run these commands:

git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/yourname/hello-docker-python.git
git push -u origin main

(Replace the URL with your own)

DONE!

You will now see all your files on GitHub:

 
 
 

  1. Go to CMD and and type below command


docker pull jenkins/jenkins:lts

  1. After that write the below command


docker run -d --name jenkins -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts

 
 
 


STEP 1: Run NGINX on Port 8080

docker run -d --name mynginx -p 8080:80 nginx

NGINX is running inside container on port 80✔ You are accessing it from host on 8080

Test:

STEP 2: Try to Reassign the SAME HOST PORT (8080) to Another Container

Now run:

docker run -d --name mynginx2 -p 8080:80 nginx

You will get an error:

Error starting userland proxy: listen tcp4 0.0.0.0:8080: bind: address already in use

Meaning:

  • Port 8080 on your machine is already occupied by mynginx

  • Docker cannot assign the same host port twice

This demonstrates port conflict.

STEP 3: Check Which Container Is Using Port 8080

Run:

docker ps

You will see:

0.0.0.0:8080->80/tcp   mynginx

STEP 4: Free Port 8080

Stop the container:

docker stop mynginx

Remove the container:

docker rm mynginx

Port 8080 is now free.

STEP 5: Run New Container Again on Port 8080

docker run -d --name mynginx2 -p 8080:80 nginx

✔ This time it works✔ Because port 8080 is free

Test:

STEP 6: Reassign to a NEW PORT Instead (Optional)

If the old port is busy, assign another port:

docker run -d --name mynginx3 -p 9000:80 nginx

Test:

What You Have Demonstrated

Concept

Explanation

Port Binding

-p HOST:CONTAINER

Port Conflict

Same host port cannot be used twice

Port Release

Stop/remove container to free port

Port Reassignment

Assign a new port like 9000


 
 
 

© 2023 by newittrendzzz.com 

  • Facebook
  • Twitter
  • Instagram
bottom of page