What is Docker?

Author

Paul van Genuchten

Published

January 5, 2023

Docker is a virtualisation technology, slightly more efficient then running a virtual machine. With docker you run a full virtual environment (container) within your PC. Most containers run a flavour of Linux and you access them as if you access a remote server. Containers are based on a docker-image, a prepared set of operating system and software. Docker images are build locally from a Dockerfile (recipe) or downloaded from a repository such as dockerhub. Learn more about docker in the Docker Overview.

In this recipe we run most examples using Docker, because in this way there is no need to install any software on your computer, which may either not be allowed, give errors due to missing dependencies or in a worse case scenario can corrupt an existing configuration.

On Windows and Apple we recommend to install Docker Desktop. Docker Desktop provides an additional panel to manage running containers. On Linux you can install docker engine. Start docker engine from the start menu, if it is not already running. A general check can be triggered by typing docker ps in a console, this will provide a notification of docker availability and running containers.

In this recipe we will use the following Docker concepts:

Instead of running containers for permanent server applications, you can also start a container to run a short process, similar to running a command line utility. The container will stop when the process is finished.

Docker exercise

  • Install Docker Desktop, verify it is running, else start it from the start menu.

  • On commandline run this command

    docker run -p 80:80 --name test uzyexe/tetris:latest
  • Open browser at http://localhost

  • Open a shell within the container

docker exec -it test /bin/bash
  • type exit to return to your pc
  • ctrl-c to stop the container

(if other processes are running on port 80, Docker will throw an error, select another port, e.g. -p 81:80, and open http://localhost:81)

Cleaning up

The virtual environments take quite some memory and CPU, you will notice this on older computers. Make sure to stop all containers after you finish using them. You can easily start them again later. docker ps (or the docker desktop window) indicate which containers are still running.

After your experiments you will notice the size of your harddisk has considerably been reduced. Images, containers, volumes all use quite some space. There is a single command to clean up everything

docker system prune -a

Only use it if you are sure you don’t want to keep any docker resources.