From Wikiversity
Jump to navigation Jump to search

Docker is a software available since 2013 that among other features performs operating-system-level virtualization also known as containerization

Features[edit | edit source]

Docker offer the following features:

Installing Docker[edit | edit source]

You can read official Docker documentation about installing Docker on your system:

On macOS you can follow official documentation which requires to create and account to download installer. You can also try: brew cask install docker or try to follow instructions:

brew install docker docker-compose docker-machine(to install docker and docker-compose)
brew cask install virtualbox
docker-machine create --driver virtualbox default
docker-machine ls
docker-machine env default
eval $(docker-machine env default)
docker run hello-world (will pull hello-world image and run it on docker)

On Ubuntu: snap install docker

Binaries[edit | edit source]

Following binaries will be installed: docker-init, docker-proxy, docker and dockerd

Verifying Docker installation[edit | edit source]

Once installed the Docker daemon, called "dockerd" should be running. You can also run docker run hello-world to verify docker correct installation.

Configuration files[edit | edit source]

  • Ubuntu: /etc/docker/daemon.json

Docker Releases (Docker Engine release notes)[edit | edit source]

Use: docker version[2] to check your version. You can download Docker CE source code from GitHub[3].

Docker Command Line[edit | edit source]

You can read official docker command line documentation in Before being able to run docker commands you will have to install Docker on your machine.

Some typical task using containers:

Docker verification commands[edit | edit source]

  • Verify correct installation: docker run hello-world

You will see some message similar to this one:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:

For more examples and ideas, visit:

Docker image and container creation[edit | edit source]

  • Create a new docker image base on alpine linux distribution and login into the new container: docker run -it alpine sh
  • Create a new docker image: docker build
    • Create a new docker image by creating a new text file with instructions, usually called Dockerfile[4]: docker build -f /path/to/a/Dockerfile .
  • Create a container: docker create
  • Generate a mediawiki:1.27 image: docker build --tag mediawiki:1.27 . (you can use -t or --tag)
  • Execute or run a container based on mediawiki:1.27 image: docker run --name wikiFGA -p -d mediawiki:1.27

Docker Container Operation[edit | edit source]

  • Start an existing container: docker start CONTAINER_ID OR CONTAINER_NAME. See also docker run and differences[5].
  • Stop an running container: docker stop container_id
  • Show only running containers:
  • Login/Connect into a running container:
    • docker exec[10] -it <my_container_name> bash
    • docker exec -it <my_container_name> sh
  • Start stopped containers: docker start $(docker ps -a -q -f status=exited)
  • Restart all containers: docker restart $(docker ps -aq) previously docker restart $(docker ps -q)-a all -q quiet[11]

See also: docker compose and docker stack

Docker images management[edit | edit source]

  • List created images: docker images[13], docker image ls (both commands seems to perform the same action, note it is image instead of images)
Images are stored in docker info | grep "Docker Root Dir"[14]
  • docker image rm[15]. See also: docker rm CONTAINER

Docker Network command line commands[edit | edit source]

Docker resource limitation[edit | edit source]

Docker: Working with remote repositories/registries[edit | edit source]

You will be using mainly the following commands docker login, docker logout, docker pull and docker push. Docker registry allow to configure notifications. [17]. Docker has a public repository called Docker Hub and cloud providers offer repositories services such as AWS Elastic Container Registry (ECR).

Docker Information[edit | edit source]

Docker Operation[edit | edit source]

Docker/cgroup Performance information[edit | edit source]

Docker Swarm[edit | edit source]

Maintenance[edit | edit source]

  • docker system prune -a remove unused and dangling images. Therefore any images being used in a container, whether they have been exited or currently running, will NOT be affected.[22]

Volumes[edit | edit source]

Docker logging[edit | edit source]

Docker support logging to format or different platforms, such as, json-file, syslog, journald, gelf, fluentd, awslogs, splunk, etwlogs, gcplogs and logentries.[24]

docker logs CONTAINER_NAME_OR_ID (Docker Community Engine only support: local, json-file and journald)
docker logs CONTAINER_NAME_OR_ID 2>&1 | grep "STRING_TO_SEARCH" (You will need to redirect outputs to be able to grep output)[25]
See for more information

Misc[edit | edit source]

Activities[edit | edit source]

  1. Read docker blog:
  2. Read Docker Engine release notes (2017) and Docker CE or Docker EE releases.
  3. Understand the difference between an image and a container, Docker Images vs. Containers:
  4. Understand the difference between docker start and docker run: See also runC
  5. Read Stackoverflow questions related to docker:

See also[edit | edit source]

References[edit | edit source]

  21. <