π οΈ 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. π
Top comments (0)