page_title: Hello world example page_description: A simple hello world example with Docker page_keywords: docker, example, hello world
This guide assumes you have a working installation of Docker. To check your Docker install, run the following command:
# Check that you have a working install
$ sudo docker info
If you get docker: command not found
or something
like /var/lib/docker/repositories: permission denied
you may have an incomplete Docker installation or insufficient
privileges to access docker on your machine.
Please refer to Installation for installation instructions.
Note:
- This example assumes you have Docker running in daemon mode. For more information please see Check your Docker install.
- If you don't like sudo then see Giving non-root access
This is the most basic example available for using Docker.
Download the small base image named busybox
:
# Download a busybox image
$ sudo docker pull busybox
The busybox
image is a minimal Linux system. You
can do the same with any number of other images, such as
debian
, ubuntu
or
centos
. The images can be found and retrieved
using the Docker index.
$ sudo docker run busybox /bin/echo hello world
This command will run a simple echo
command, that
will echo hello world
back to the console over
standard out.
Explanation:
Video:
See the example in action
Note:
- This example assumes you have Docker running in daemon mode. For more information please see Check your Docker install.
- If you don't like sudo then see Giving non-root access
And now for the most boring daemon ever written!
We will use the Ubuntu image to run a simple hello world daemon that will just print hello world to standard out every second. It will continue to do this until we stop it.
Steps:
CONTAINER_ID=$(sudo docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done")
We are going to run a simple hello world daemon in a new container made
from the ubuntu
image.
sudo docker logs $container_id
Check the logs make sure it is working correctly.
sudo docker attach --sig-proxy=false $container_id
Attach to the container to see the results in real-time.
Exit from the container attachment by pressing Control-C.
sudo docker ps
Check the process list to make sure it is running.
sudo docker stop $container_id
Stop the container, since we don't need it anymore.
sudo docker ps
Make sure it is really stopped.
Video:
See the example in action
The next example in the series is a Node.js Web App example, or you could skip to any of the other examples: