Docker Basics

Essential Docker system commands for beginners

Step 1: Download Node.js Code

First, download the Node.js application code by clicking the button below:

Download Node.js Code

Step 2: Install Docker Extensions in VS Code

Download the Docker extension in VS Code from Microsoft. This will install two extensions:

After installing the extensions, open the Node.js program in VS Code.

Step 3: Add Docker Files to Your Project

Follow these steps to add Docker files to your Node.js project:

1

Open Command Palette

Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac) to open the command palette.

2

Search for Docker Add

Type "Docker add" and select the option "Docker: Add Docker Files to Workspace..."

3

Select Application Platform

Choose Node.js since your application is written in Node.js.

4

Select Package.json Location

Select the root package.json file.

5

Enter Port Number

Enter 3000 as the port your application runs on.

6

Skip Docker Compose

When asked if you want to add a Docker Compose file, select "No".

The extension will generate two Docker files: .dockerignore and Dockerfile.

Step 4: Build a Docker Image

Now you can build an image using the command palette:

1

Search for Docker Build

In the command palette, search for "docker build" and select the option "Docker Images: Build Image..."

# This will run build commands automatically and create an image
# You can check the image using: docker images

Step 5: Run Your Docker Image

1

Run the Image via Command Palette

In the command palette, type "docker run" and select "Docker Images: Run".

2

Select Image

Select your Docker image named "myexpressapp".

Alternative Method

If the command palette method doesn't work, you can run the image using the Docker extension:

  1. Click on the Docker extension icon in VS Code
  2. Go to the "Images" section
  3. Find your image named "myexpressapp"
  4. Right-click on the image
  5. Select "Run" from the context menu
# After running the image, check in your browser at: http://localhost:3000

Managing Docker Containers

When you click on the Docker extension icon, you'll see two main sections:

Containers

  • Shows running containers
  • Shows stopped containers
  • Images are listed below the containers

Images

  • Shows every image in your local PC
  • You can manage images from here

Container Management

Stopping Containers

To stop a running container:

  • Go to the Containers section
  • Right-click on your container
  • Select "Stop" or "Remove"

Starting Containers

To start a container:

  • Go to the Images section
  • Right-click on the container name
  • Select "Start" or "Remove"

Docker Command Quick Reference

Command Description
docker images List all Docker images on your system
docker ps List running containers
docker ps -a List all containers (running and stopped)
docker stop <container_id> Stop a running container
docker rm <container_id> Remove a container
docker rmi <image_id> Remove an image