Docker Run Hello-World
First things first!
Run a hello-world
container using this simple command:
docker run hello-world
Run a Web Server Container
Now, run a web server container using the nginx
image from Docker Hub:
Hint 1: 'docker run' command format π‘
The only mandatory argument for the docker run
command is the container image name,
which in its simplest form can be just nginx
.
Unlike the hello-world
container that exited right after printing the welcome message,
the Nginx container will typically keep running indefinitely.
To terminate the Nginx container running in the foreground,
you can simply press Ctrl+C
to send the SIGINT
signal to the container:
Use a Non-Docker Hub Image
Both hello-world
and nginx
containers used the Docker Hub library images,
stored somewhere on Docker's servers (Docker as in the company, not the software).
However, you can also run containers from images stored in other container registries.
Run a container from playground's local registry image:
docker run registry.iximiuz.com/acme:v1
Hint 2: Image name format π‘
If you're curious about the image name format, and how come nginx
is the same
as nginx:latest
and docker.io/library/nginx:latest
, here's a visual explanation
(but no worries if it looks a little overwhelming -
you'll get the hang of it once we move on to more container image related challenges):

Run an Interactive Shell Container
Finally, start an interactive Debian shell using the docker run -it
command:
When you're done with exploring the interactive shell,
terminate the debian
container:
Hint 3: How to exit an interactive container shell π‘
Similar to the nginx
and acme:v1
containers,
the debian
container will keep running in the foreground until you terminate it.
However, unlike the nginx
container, simply pressing Ctrl+C
won't be enough to stop the interactive shell -
the signal will be intercepted by the shell and forwarded to a whatever nested process you may have started
in the container (or simply ignored if no process is running).
To exit the interactive shell, you can use the exit
command in the shell itself
or press Ctrl+D
to send the EOF
signal to the container.
Alternatively, you can stop the container with docker stop
or docker kill
from another terminal.
Congratulations! You've run your first containers and experienced the most typical scenarios of using the foreground docker run
command.
Now, let's move on to the next challenge and run a container in the background.
Level up your Server Side game β Join 11,000 engineers who receive insightful learning materials straight to their inbox