Docker Basics: Creating and Running Container

In today’s fast-paced development world, containerization has become a must-know skill — and Docker leads the way. Whether you’re a developer, system administrator, or just curious about modern software practices, understanding Docker is a great step forward. In this post, we’ll cover Docker Basics: Creating and Running Container so you can start your journey into containerization with confidence.

What is Docker?

Docker is an open-source platform designed to automate the deployment, scaling, and management of applications inside lightweight containers. These containers package your application’s code, libraries, and dependencies into a single, portable unit — ensuring it works reliably across different computing environments.

In simpler words, think of a container as a neat, self-sufficient box where your application lives.

Why Use Docker?

  • Consistency: Works on any machine, anywhere.
  • Isolation: Keeps apps separate and clean.
  • Efficiency: Lightweight and faster than traditional virtual machines.
  • Scalability: Perfect for deploying and managing microservices.

Now, let’s dive into the core: creating and running a Docker container!

Setting Up Docker

Before we begin, make sure Docker is installed on your system:

  • Windows/Mac users: Download Docker Desktop from Docker’s official site.
  • Linux users: Install using your package manager, e.g., sudo apt install docker.io for Ubuntu.

Once installed, verify Docker is running with:

bashCopyEditdocker --version

You should see the Docker version installed.


Creating and Running Your First Container

Let’s walk through a simple example using the popular hello-world image.

Step 1: Pull an Image

An image is like a blueprint for a container. Start by pulling the hello-world image:

bashCopyEditdocker pull hello-world

Step 2: Run the Container

Now, let’s run a container using that image:

bashCopyEditdocker run hello-world

Docker will create a container from the hello-world image and execute it. You’ll see a friendly message confirming everything is working.

Step 3: List Running Containers

To see containers that are currently running:

bashCopyEditdocker ps

To see all containers (including ones that have stopped):

bashCopyEditdocker ps -a

Step 4: Stop and Remove Containers

If you have a container running and want to stop it:

bashCopyEditdocker stop <container_id>

To remove a container:

bashCopyEditdocker rm <container_id>

(You can find the container ID by running docker ps -a.)


Bonus: Building Your Own Docker Image

Want to create your own image? Here’s a lightning-fast overview:

  1. Create a file called Dockerfile:
DockerfileCopyEditFROM alpine
CMD ["echo", "Hello from my Docker container!"]
  1. Build the image:
bashCopyEditdocker build -t my-first-image .
  1. Run your new container:
bashCopyEditdocker run my-first-image

Just like that, you’ve created and run your very own container!


Final Thoughts

Learning Docker Basics: Creating and Running Container opens up a whole world of possibilities — from easier development environments to scalable cloud deployments. This is just the beginning! As you get more comfortable, you’ll explore Docker Compose, custom networks, volumes, and much more.

Stay tuned for more beginner-friendly Docker tutorials!

Leave a Comment

Your email address will not be published. Required fields are marked *