Docker

From wikieduonline
Revision as of 13:50, 22 December 2019 by Welcome (talk | contribs) (→‎Maintenance)
Jump to navigation Jump to search

Features

Docker offer the following features:

Installing Docker

You can read official Docker documentation about installing Docker on your system: https://docs.docker.com/install/.

On macOS you can follow official documentation https://docs.docker.com/docker-for-mac/install/ which requires to create and account to download installer. You can also try: brew cask install docker or try to follow https://pilsniak.com/how-to-install-docker-on-mac-os-using-brew/ 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 (officially provided by Canonical)

Binaries

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

Verifying Docker installation

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

  • Ubuntu: /etc/docker/daemon.json

Docker Releases (Docker Engine release notes)

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

Docker Command Line

You can read official docker command line documentation in https://docs.docker.com/engine/reference/commandline/docker/. Before being able to run docker commands you will have to install Docker on your machine.

Some typical task using containers:

Docker verification commands

  • 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.
    (amd64)
 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:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

Docker image and container creation

  • 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 0.0.0.0:9090:80 -d mediawiki:1.27

Docker Container Operation

  • 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

Docker Network command line commands

Docker resource limitation

Docker: Working with remote repositories/registries

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

Docker Operation

Docker/cgroup Performance information

Docker Swarm

Maintenance

  • 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]. See also: docker system info

Volumes


Secrets

Docker logging

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

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)[26]
See https://docs.docker.com/config/containers/logging/ for more information

Misc

Activities

  1. Read docker blog: https://blog.docker.com/
  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: https://stackoverflow.com/a/26960888
  4. Understand the difference between /docker start/ and /docker run/: https://stackoverflow.com/questions/34782678/difference-between-running-and-starting-a-docker-container. See also runC
  5. Read Stackoverflow questions related to docker: https://stackoverflow.com/questions/tagged/docker?tab=Votes
  6. Read about Docker Image Manifest Version 2, Schema 2: https://github.com/docker/distribution/blob/fda42e5ef908bdba722d435ff1f330d40dfcd56c/docs/spec/manifest-v2-2.md

See also


Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Source: https://en.wikiversity.org/wiki/DevOps/Docker

Template:Subpage navbar

  1. https://docs.docker.com/engine/reference/commandline/pull/
  2. https://docs.docker.com/engine/reference/commandline/version/
  3. https://github.com/docker/docker-ce/releases
  4. https://docs.docker.com/engine/reference/builder/
  5. https://stackoverflow.com/questions/34782678/difference-between-running-and-starting-a-docker-container
  6. https://docs.docker.com/engine/reference/commandline/container_ls/
  7. https://docs.docker.com/engine/reference/commandline/ps/
  8. https://www.docker.com/blog/whats-new-in-docker-1-13/
  9. https://stackoverflow.com/a/45254760
  10. https://docs.docker.com/engine/reference/commandline/exec/
  11. https://stackoverflow.com/questions/38221463/command-for-restarting-all-running-docker-containers
  12. https://docs.docker.com/config/containers/start-containers-automatically/#use-a-restart-policy
  13. https://docs.docker.com/engine/reference/commandline/images/
  14. https://stackoverflow.com/questions/19234831/where-are-docker-images-stored-on-the-host-machine
  15. https://docs.docker.com/engine/reference/commandline/image_rm/
  16. https://docs.docker.com/network/links/
  17. https://docs.docker.com/registry/notifications/
  18. http://manpages.ubuntu.com/manpages/disco/man1/docker-inspect.1.html
  19. https://docs.docker.com/engine/reference/commandline/image_inspect/
  20. https://docs.docker.com/engine/reference/run/
  21. <https://docs.docker.com/engine/reference/commandline/swarm/
  22. https://stackoverflow.com/a/45143234
  23. https://stackoverflow.com/questions/30133664/how-do-you-list-volumes-in-docker-containers
  24. https://www.docker.com/blog/docker-secrets-management/
  25. https://docs.docker.com/config/containers/logging/configure/
  26. https://stackoverflow.com/questions/34724980/finding-a-string-in-docker-logs-of-container
  27. https://docs.docker.com/engine/reference/commandline/tag/

Advertising: