Note: These examples will work on Linux out of the box, but might need to enable experimental futures on windows to run (see LCOW under Advance topics). The basics for each command is still same on Windows.
The best way to install Docker on your workstation is to follow the official guide provided by Docker:
The best way to test if Docker is running on your workstation is to run the hello-world image, if the image is not already download on the local workstation, Docker with first pull it from the registry and then run it.
We can test if Docker is running properly by entering the following command in the Terminal window (Command Prompt in Windows):
docker info docker version docker run hello-world
You can pull any image out-of-the-box from the Docker Hub repository by:
docker pull busybox
List pulled images
You can check all the pulled images stored locally:
REPOSITORY TAG IMAGE ID CREATED SIZE busybox latest 59788edf1f3e 6 days ago 3.41MB hello-world latest 4ab4c602aa5e 4 weeks ago 263kB
You can run any image in Docker with:
docker run busybox
The Docker Engine will create a new container, and run it. In this case the container will finish execution and exit. This mode is useful when you just want to run a command or script, and turn off the container:
docker run busybox uname -a
This will print the kernel information, as the container sees it.
To be able to interact with
busybox, you need to run:
docker run -it busybox
Now you have access to busybox. It can be used as if it was installed directly on your local workstation. Do remember, anything you save might be lost as soon as, you logout.
Another way to run a container, is as a daemon (background service).
docker run -d --name=busy busybox /bin/sh -c "while true; do echo hello world; sleep 1; done"
You can check if the container is running by:
docker attach busy hello world hello world
You can exit the by pressing CTRL+C, the container will continue to run in the background.
Stop a running container with:
docker stop [name|container_id]
docker stop ex1
List running containers
The easiest way to check what containers are running is:
List all the containers, including stopped:
docker ps -a
A container can be removed with:
docker rm [name|container_id]
docker rm ex1
Tell Docker to remove the container once finished running:
docker run --rm -ti busybox
An Docker Image can be removed with:
docker rmi [image_name]
docker rmi busybox