DEV Community

Cover image for Dive into Docker: A Hands-On Lab for Getting Started
Mary Ajayi
Mary Ajayi

Posted on • Originally published at hashnode.com

Dive into Docker: A Hands-On Lab for Getting Started

Containerization has revolutionized the way software is developed, deployed, and managed. Docker, a leading containerization platform, has gained immense popularity for its simplicity and efficiency.

In this hands-on lab, we will embark on a journey to explore the fundamentals of Docker, enabling you to harness the power of containerized applications.

Here's a simple hands-on lab that covers the basics:

Lab 1: Installing Docker

Install Docker:

Go to the Docker website and download the Docker Desktop for your operating system.
Follow the installation instructions for your platform.
Verify Installation:
Open a terminal (or command prompt) and run the following commands:
docker --version docker-compose --version

Lab 2: Running Your First Container

Step 1: Get the sample application

If you have git, you can clone the repository for the sample application. Otherwise, you can download the sample application. Choose one of the following options.
Clone with git Download
Use the following command in a terminal to clone the sample application repository.
PowerShell
$ git clone https://github.com/docker/welcome-to-docker
Step 2: View the Dockerfile in your project folder
To run your code in a container, the most fundamental thing you need is a Dockerfile. A Dockerfile describes what goes into a container. This sample already contains a Dockerfile. For your own projects, you'll need to create your own Dockerfile. You can open the Dockerfile in a code or text editor and explore its contents.

Step 3: Build your first image

You always need an image to run a container. In a terminal, run the following commands to build the image. Replace /path/to/welcome-to-docker/ with the path to your welcome-to-docker directory.
PowerShell
docker build -t welcome-to-docker .
In the previous command, the -t flag tags your image with a name, welcome-to-docker in this case. And the . lets Docker know where it can find the Dockerfile.
Building the image may take some time. After your image is built, you can view your image in the Images tab in Docker Desktop.

Step 4: Run your container

To run your image as a container:
In Docker Desktop, go to the Images tab.

Next to your image, select Run.

Expand the Optional settings.
In Host port, specify 8089

Select Run.

Step 5: View the frontend

You can use Docker Desktop to access your running container. Select the link next to your container in Docker Desktop or go to http://localhost:8089 to view the frontend.

Step 6: Stop your container

The container continues to run until you stop it. To stop the container in Docker Desktop, go to the Containers tab and select the Stop icon in the Actions column of your container.

Summary

In this walkthrough, you built your own image and ran it as a container. In addition to building and running your own images, you can run images from Docker Hub.

Reference

Docker Documentation - https://docs.docker.com/guides/walkthroughs/run-a-container/

Top comments (0)