Containerization has changed how software is developed, deployed, and managed. Docker allows developers to package applications with all dependencies into portable containers. This blog shows hands-on experience with Docker, from installation to running a frontend app.
- Lab 1: Installing Docker
- Lab 2: Running Your First Container
- Step 1: Clone Sample Application
- Step 2: Explore the Dockerfile
- Step 3: Build the Docker Image
- Step 4: Run the Container
- Step 5: Access the application
- Step 6: Stop the Container
- Summary
Lab 1: Installing Docker
Download Docker Desktop
Docker Desktop includes the Docker Engine, CLI, and Docker Compose, providing everything you need to build and run containers locally.
Go to the https://www.docker.com/
and download Docker Desktop for your operating system.
Run the installer and follow the on-screen instructions for your platform. After installation, restart your computer if required.
This process sets up Docker’s core components and ensures that your system is ready to manage containers.
Verify Installation
Output
These commands confirm that Docker and Docker Compose are installed and ready to use.
Lab 2: Running Your First Container
This step verifies that Docker can pull images from Docker Hub and run them as containers on your system.
Run a simple test container:
Expected Output:
Docker will download a small test image and display a success message.
Step 1: Clone Sample Application
Cloning the repository gives you all the source code and the Dockerfile needed to build your containerized application.
Clone the sample application repository:
Step 2: Explore the Dockerfile
The Dockerfile acts as a blueprint that tells Docker how to set up your container consistently.
The Dockerfile defines the environment for your app:
Base image: node:22-alpine
Working directory: /app
Copy application files and install dependencies
Build the app and remove unnecessary files
Expose port 3000 and serve the app using serve -s build
Step 3: Build the Docker Image
Building an image packages your app and all its dependencies into a single, portable unit that can run anywhere Docker is installed.
Build the Docker image using:
Expected Output
Step 4: Run the Container
Running a container launches your application in an isolated environment. Port 3000 is mapped so you can access the app from your browser.
Run your image as a container:
Optionally
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: Access the Application
This confirms that your containerized application is running correctly and accessible locally.
Open a browser and go to:
Optionally
Select the link next to your container in Docker Desktop to access the application.
Step 6: Stop the Container
Stopping the container frees system resources. docker ps shows which containers are currently running.
List running containers and stop yours
Optionally
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 lab, you learned how to install Docker, build a container, and run it locally. You now understand how Docker packages applications and their dependencies, making them portable and consistent across environments.
Top comments (0)