🛠️ Step 1: Install Docker
First, ensure Docker is installed on your machine.
You can install Docker Desktop from https://docs.docker.com/get-docker/.
Check if Docker is installed correctly:
docker --version
🛠️ Step 2: Create a Simple Application
Let's create a simple app. For example, a basic Python app.
Create a folder and files:
mkdir my-docker-app
cd my-docker-app
touch app.py
app.py:
print("Hello, Docker World!")
🛠️ Step 3: Create a Dockerfile
Inside the same folder, create a Dockerfile:
touch Dockerfile
Dockerfile content:
`FROM python:3.10-slim
WORKDIR /app
COPY . .
CMD ["python", "app.py"]
🛠️ Step 4: Build the Docker Image
Now, build the image using:
docker build -t your_dockerhub_username/my-docker-app:latest .
Note: Replace your_dockerhub_username with your actual DockerHub username.
🛠️ Step 5: Run the Docker Container
Test your image by running:
docker run your_dockerhub_username/my-docker-app:latest
You should see:
Hello, Docker World!
🛠️ Step 6: Login to DockerHub
Before pushing the image, log in to your DockerHub account:
docker login
Enter your username and password when prompted.
🛠️ Step 7: Push the Image to DockerHub
Now, push your image:
docker push your_dockerhub_username/my-docker-app:latest
After successful push, you can visit:
👉 https://hub.docker.com/
and find your repository under your profile.
🛠️ Bonus: Pulling and Running the Image from Any Machine
Anyone (including you) can pull and run your image using:
docker pull your_dockerhub_username/my-docker-app:latest
docker run your_dockerhub_username/my-docker-app:latest
📌 Conclusion
That's it!
You have successfully:
Created a Docker image
Tested it locally
Logged into DockerHub
Pushed your image to DockerHub!
Now your app can be shared globally or deployed to production. 🚀