Introduction
Verifying your Docker setup with a "Hello, World" container is a fundamental step. We'll explore four different methods:
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");
}
}