From Wikiversity
< DevOps(Redirected from Docker)
Jump to navigation Jump to search

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

Installing Docker[edit]

You can read official Docker documentation about installing Docker on your system: On macOS you can follow official documentation or also run brew install docker docker-compose[1].

Verifying Docker installation[edit]

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

Docker Engine Releases[edit]

  • April 2015: Docker Engine 1.6.0 [2]. Logging drivers, json-file, syslog, or none
  • October 1, 2014: Docker Engine 1.3 launches[3], and introduces docker exec command.
  • August 1, 2014: Docker Engine 1.2 launches

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

Docker command line[edit]

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]

  • 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]

  • 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[6]: 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 local container operation[edit]

  • Start an existing container: docker start
  • Stop an running container: docker stop container_id
  • Show only running containers:docker ps or docker container ls
  • Show containers (running or not): docker ps -a or docker container ls --a
  • Login/Connect into a running container:
    • docker exec -it <my_container_name> bash
    • docker exec -it <my_container_name> sh

Start configuration behavior and restart policy[7][edit]

To configure the start configuration behavior or the restart policy for a container, use the --restart flag when using the docker run command. The value of the --restart flag can be any of the following:

  • Do not automatically restart the container. (the default): no
  • Restart the container if it exits due to an error, which manifests as a non-zero exit code: on-failure
  • Restart the container unless it is explicitly stopped or Docker itself is stopped or restarted: unless-stopped
  • Always restart the container if it stops: always

The following example starts a Redis container and configures it to always restart unless it is explicitly stopped or Docker is restarted:

$ docker run -dit --restart unless-stopped redis

Docker images management[edit]

  • List created images: docker images, docker image ls (both commands seems to perform the same action)

Docker Network command line commands[edit]

  • docker network ls
  • docker network inspect

Docker resource limitation[edit]

  • Limit container CPU usage to 0.5 cpus: docker run -it --cpus=".5" docker_image /bin/bash

Docker: Working with remote repositories/registries[edit]

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

Docker Information[edit]

Docker logging[edit]

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

See also[edit]