Introduction

Verifying your Docker setup with a "Hello, World" container is a fundamental step. We'll explore four different methods:

  1. Run Docker's hello-world image.
  2. Print "Hello, world" from another basic Docker image.
  3. Write a simple "Hello, World" Java program and run it in a Docker container.
  4. Execute a "Hello, World" Java program using Gradle and Docker.

Make sure Docker is installed before proceeding. On Linux, add your username to the "docker" group during installation to avoid using sudo.

Run Docker Hello World Image

The simplest way to confirm a correct Docker installation is to run the hello-world Docker image:

$ docker run hello-world

This command downloads the image from Dockerhub (if not present) and runs it. A successful run displays a specific output.

Print "Hello, World" from Another Docker Image

Use a basic Docker image to print "Hello, World":

$ docker run alpine:latest "echo" "Hello, World"

This command downloads the Alpine base image, creates a Docker container, and executes the echo command. The output should display "Hello, World."

Write and Run a Simple Java Program

Take it a step further by writing a "Hello, World" Java program and running it in a Docker container.

Create HelloWorld.java

Create a simple Java program:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World");
    }
}