Skip to main content

Command Palette

Search for a command to run...

Creating a Docker file From Scratch to Docker Hub: Building and Deploying Your First Docker Image on Ubuntu

Building a docker file

Published
3 min read
Creating a Docker file   From Scratch to Docker Hub: Building and Deploying Your First Docker Image on Ubuntu

Getting Started with Docker: Building, Tagging, and Pushing Your First Image

Docker has become a cornerstone of modern software development, allowing developers to package applications and their dependencies into lightweight, portable containers. In this guide, we’ll walk you through a hands-on process—starting from setting up your working directory on Ubuntu Linux, creating a Dockerfile, building your first Docker image, and pushing it to Docker Hub for future use or deployment. Whether you’re a beginner exploring containerization or a developer streamlining your workflow, this step-by-step approach will give you a solid foundation to start working with Docker efficiently.

Open your Ubuntu Linux terminal.

Run - sudo su - with your password…. To enter your root account.

Run - apt update To update your package.

Run - mkdir (your directory name) To create a directory.

Run - cd (yourdirectoryname) To enter your directory.

Run - vi dockerfile Dockerfile must be written as dockerfile. To open a text editor.

INSIDE THE FILE TEXT EDITOR TYPE INSTRUCTIONS:

FROM ubuntu - specifying ubuntu as our base image

LABEL maintainer=(your email address) The person’s maintaining the files email.

CMD “echo“, “welcome“ - To echo a message.

WORKDIR /app

COPY . /app

After writing the instructions type esc:wq to save and exit.

BUILD AN IMAGE AND PUSH IT TO DOCKER HUB

Run - docker -t (name of your image) . & enter To build an image.

Run - docker ps -a To see the image you build.

Navigate back to your Firefox and search for Docker Hub and sign in Or sign in to Docker Desktop.

Click on Create a repository, so that we can push our image here.

Give it a name, your app description, select Add README, and create repository.

On the right side under public view, there is a docker push command and copy.

Navigate back to your Linux terminal.

Run - docker login —username=(your dockerhub username) and enter.

insert your password and enter. To log in to your Docker Hub from your terminal.

Run - docker tag (your image name) (your docker username)/(repo name):latest and enter.

Run - docker inspect (name of the image) and scroll down to see your Dockerfile content and all.

Run - paste the Docker push command you copied from your Docker Hub account. To push.

Navigate back to your Docker Hub to check if your container image is pushed successfully.

The essence is for self-keeping if you want to use the image to create another container.

Navigate back to the terminal to create another container with the image we just pushed.

Run - docker run -d —name (name of your container) -p 8080:80 (the image name you’ve pushed) OR

Run - docker run -d —name (name of your container) (the name of your image) To create a container.

Run - docker ps -a To check if created successfully.

Success…

I hope you find my post helpful, and it can guide you through the process with no difficulties.

Join me on this cloud adventure and elevate your tech skills! Sign in to the Azure portal, follow my easy instructions, and unleash the power of being in the cloud.

Subscribe to my blog for more tech tips and tricks that will keep you ahead in the digital game. Your journey to mastering Cloud computing starts here!

🌟 Thank you for being a part of this incredible journey! Together, let's unlock new opportunities and make the most out of our digital experiences. Happy computing! 🌟