Dive Into Docker: A Hands-On Lab For Getting Started

mabis12

Abisola Adesegun

Posted on September 20, 2024

Dive Into Docker: A Hands-On Lab For Getting Started

Table of contents
Lab 1: Installing Docker
Lab 2: Running Your First Container
Step 1: Get the sample application
Step 2: View the Dockerfile in your project folder
Step 3: Build your first image
Step 4: Run your container
Step 5: View the frontend
Step 6: Stop your container
Summary

Docker is a popular tool for creating, deploying, and running applications inside containers. Containers allow developers to package up an application with all the parts it needs, such as libraries and other dependencies, and ship it all out as one package. Here’s a hands-on lab to help you get started with Docker, covering everything from installation to creating and managing containers.

Lab 1: Install Docker

  • Install Docker Desktop from the official Docker website. It provides a simple way to install Docker on your machine.

  • Verify the installation by running:

Image description

Image description

Lab 2: Run Your First Docker Container
Containers are lightweight and isolated, much like a VM, but more efficient. Let’s run your first container.

Step 1: Get a Sample application
Docker can build images automatically by reading the instructions from a Dockerfile.

Image description

Image description

Step 2: View the Dockerfile in your application
A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.

Image description

Step 3: Build your first Docker Image

Build the image:
The docker build command uses the Dockerfile to build a new image. You see that Docker downloaded a lot of "layers". You are supposed to start building from the node:18-alpine image. But, since you didn't have that on your machine, Docker needed to download the image.

After Docker downloaded the image, the instructions from the Dockerfile copied in your application and used yarn to install your application's dependencies.

The -t flag tags your image while the . at the end of the docker build command tells Docker that it should look for the Dockerfile in the current directory.

Image description

Image description

Step 4: Run your container

  • In Docker Desktop, go to the Images tab.

Image description

  • click on image and select Run.

Image description

  • Expand the Optional settings.

Image description

  • Type in container name and specify 8089 in Host port

Image description

  • Select Run.

Step 5: View your frontend
Now, we'll use Docker Desktop to access your running container. Select the link next to your container in Docker Desktop.

Image description

Image description

Step 6: Stop your container
Use your container id using command below.

Image description

Image description

Image description

Summary
This hands-on labs offer a basic introduction to Docker. By the end of it, you should have a good understanding of how Docker works and how you can use it to containerize your applications.

💖 💪 🙅 🚩
mabis12
Abisola Adesegun

Posted on September 20, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related