Docker Basics

Essential Docker system commands for beginners

Docker Hub and Image Management

This guide walks you through the process of working with Docker Hub, building Docker images, tagging them, and managing different versions of your application.

Step 1: Download Node.js Code

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

Download Node.js Code
1

Docker Hub Login

Head to hub.docker.com and make sure you can log in.

Ensure you have your Docker Hub credentials ready for the next steps.

2

Add a Dockerfile

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.

3

Build the Image

Build the Docker image with your Docker Hub username as the tag.

docker build -t <YourRegistryName>/express:v1 .

Explanation:

  • docker build → Builds an image from a Dockerfile
  • -t <YourRegistryName>/express:v1 → Tags the image with your username and version
  • . → Build context (current directory)
4

Push the Image

Push the built image to Docker Hub.

docker push <YourRegistryName>/express:v1

Verification:

Back in hub.docker.com, locate the image you just pushed to verify it was uploaded successfully.

5

Pull the Image from Docker Hub

Let's first delete the local image and pull it back from Docker Hub to verify the process works.

Remove the local image:

docker rmi <YourRegistryName>/express:v1

Pull the image:

docker pull <YourRegistryName>/express:v1

Purpose:

This step verifies that your image is correctly stored in Docker Hub and can be retrieved by you or others.

6

Create Version 2

Using the commands you learned earlier, build and push a new version to Docker Hub.

Build the v2 image:

docker build -t <YourRegistryName>/express:v2 .

Push the v2 image:

docker push <YourRegistryName>/express:v2

Verification:

Back in hub.docker.com, locate the v2 image you just pushed to verify both versions are available.

7

Cleanup

Remove the local images to clean up your system.

Remove the local v1 image:

docker rmi <YourRegistryName>/express:v1

Remove the local v2 image:

docker rmi <YourRegistryName>/express:v2

Note:

Your images remain safely stored in Docker Hub and can be pulled again anytime.

8

Delete Images from Docker Hub

If you need to remove images from your Docker Hub repository, follow these steps:

Method 1: Using Docker Hub Web Interface

  1. Log in to your Docker Hub account
  2. Navigate to your repositories from the top menu
  3. Click on the repository containing the image you want to delete
  4. Go to the "Tags" tab
  5. Check the boxes next to the tags you want to delete (v1, v2, etc.)
  6. Click the "Delete" button and confirm the action

Method 2: Using Docker CLI (Experimental)

Note: The Docker CLI currently doesn't support deleting images directly from Docker Hub. You must use the web interface.

However, you can delete local images using:

docker rmi <YourRegistryName>/express:v1 <YourRegistryName>/express:v2

Important Considerations:

  • Deleting images from Docker Hub is permanent and cannot be undone
  • If other users or systems depend on these images, they will no longer be able to pull them
  • Consider using private repositories if you need more control over image access