User Tools

Site Tools


devops:docker

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
devops:docker [2023/11/01 07:15] – removed - external edit (Unknown date) 127.0.0.1devops:docker [2025/03/22 23:03] (current) skipidar
Line 1: Line 1:
 +===== Dоcker =====
  
 +
 +==== Hyper-V ====
 +The newest Version uses Hyper-V.
 +
 +**The Hyper-V has a bug - enabling a Virtual Switch Disabled WiFi adapter, which makes it useless on Laptops.**
 +So it is recommended to use the old version, with docker-machine, based on Oracle's VirtualBox.
 +
 +<code>
 +
 +Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All
 +
 +</code>
 +
 +
 +Packages / Containers with applications, which can be executed on a tiny Linux-daemon.
 +Pro is the automatical shipment
 +
 +  - setup on Windows
 +    - create a local docker-host
 +  - install existing Container locally (DB, AppServer, HTTP daemon)
 +  - access the container. Modify WebServer page, ubuntu via console, deploy to jboss, setup nginx as a reverse proxy
 +  - wire Containers together
 +  - install same Container to AWS
 +  - make a SWARM cluster from them
 +  - enroll them automatically all together locally 
 +  - enroll them automatically all together to AWS
 +  - setup an own registry
 +  - create a docker dontainer
 +  - test online services, ship, run your container from there
 +  - setup a local registry
 +
 +
 +== Commands ==
 +^ Command                                                                                                           ^ Description                                                                                                                                                                                                                                                                                                                                                                                                                                                              ^
 +| commit                                                                                                            | creates a new image from a container                                                                                                                                                                                                                                                                                                                                                                                                                                     |
 +| run                                                                                                               | runs a container from an image                                                                                                                                                                                                                                                                                                                                                                                                                                           |
 +| start                                                                                                             | starts an EXISTING, STOPPED container                                                                                                                                                                                                                                                                                                                                                                                                                                    |
 +| stop                                                                                                              | stops an EXISTING, RUINNING container                                                                                                                                                                                                                                                                                                                                                                                                                                    |
 +| exec                                                                                                              | executes a command INSIDE of EXISTING, RUNNING container                                                                                                                                                                                                                                                                                                                                                                                                                 |
 +| docker search NAME                                                                                                | Search for an image with the specified name.                                                                                                                                                                                                                                                                                                                                                                                                                             |
 +| docker pull NAME                                                                                                  | Pull an image into your local file system with he specified name.                                                                                                                                                                                                                                                                                                                                                                                                        |
 +| docker version                                                                                                    | Prints the docker version to the standard output.                                                                                                                                                                                                                                                                                                                                                                                                                        |
 +| docker run -td -p 80:8080 NAME                                                                                    | Run a docker image with daemon mode with port 80 forwarded to port 8080 in the container.                                                                                                                                                                                                                                                                                                                                                                                |
 +| docker start CONTAINERID                                                                                          | Start a stopped container.                                                                                                                                                                                                                                                                                                                                                                                                                                               |
 +| docker stop CONTAINERID                                                                                           | Stop a container with the specified id.                                                                                                                                                                                                                                                                                                                                                                                                                                  |
 +| docker ps                                                                                                         | List all RUNNING container                                                                                                                                                                                                                                                                                                                                                                                                                                               |
 +| docker ps -a                                                                                                      | List all container                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
 +| docker login -u USERNAME -p PASSWORD -e EMAIL registryURL                                                         | Login to a registry with -u for username -p for password and -e for email.                                                                                                                                                                                                                                                                                                                                                                                               |
 +| docker rm CONTAINERID                                                                                             | Remove a container.                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
 +| docker images -a                                                                                                  | list all images                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
 +| docker rmi IMAGEID                                                                                                | Remove an image.                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
 +| docker logs                                                                                                       | Fetch the logs from a docker container.                                                                                                                                                                                                                                                                                                                                                                                                                                  |
 +| docker inspect IMAGE_NAME                                                                                         | echo JSON with describtion                                                                                                                                                                                                                                                                                                                                                                                                                                               |
 +| docker run -d IMAGE_NAME                                                                                          | Detach. Means run in background. Even when you quit the container. Dont block the console with STDOUT.                                                                                                                                                                                                                                                                                                                                                                   |
 +| docker run -P IMAGE_NAME                                                                                          | expose ports on DOCKER_HOST. Port 5000 of container is redirected to localhost:5000                                                                                                                                                                                                                                                                                                                                                                                      |
 +| docker exec -it CONTAINERID COMMAND                                                                               | <WRAP>  You can find out the COMMAND available for CONTAINERID by doing //docker ps//.   <code> $ docker ps  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS NAMES 625ad92a1f53        ubuntu:latest       "/bin/bash"         15 seconds ago      Up 14 seconds  $ docker exec -it 625ad92a1f53 "/bin/bash"  </code></WRAP>                                                                                   |
 +| docker inspect CONTAINER_NAME                                                                                     | Provide ALL data about the container.                                                                                                                                                                                                                                                                                                                                                                                                                                    |
 +| docker-machine ls                                                                                                 | list existing hosts                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
 +| docker-machine create --driver virtualbox HOSTNAME                                                                | create host                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
 +| docker-machine rm HOSTNAME                                                                                        | remove host                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
 +| docker-machine restart HOSTNAME                                                                                   | restarts the host                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
 +| <code>start http://$(docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" grave_thompson):81</code>  | starts the container "grave_thompson", by requesting its IP by container name                                                                                                                                                                                                                                                                                                                                                                                            |
 +| docker attach CONTAINERNAME                                                                                       | Shows what is happening inside the container. You can even kill the process by CTRL+C                                                                                                                                                                                                                                                                                                                                                                                    |
 +| docker commit jira skipidar/atlassian-jira:1.0                                                                    | store the docker container as a new image                                                                                                                                                                                                                                                                                                                                                                                                                                |
 +| docker push skipidar/atlassian-jira                                                                               | save docker image to a repository "skipidar/atlassian-jira"                                                                                                                                                                                                                                                                                                                                                                                                              |
 +| docker exec <CONTAINER> <COMMAND>                                                                                 | <WRAP>  Executes a command in a container. E.g. to show which processes are running in container:    <code> PS D:\webserver> docker exec ubuntu2 ps -f UID         PID   PPID  C STIME TTY          TIME CMD root         51      0  0 15:09 ?        00:00:03 /usr/bin/python /usr/bin/ajenti-panel -d root        130      0  0 16:29 ?        00:00:00 nginx: master process /usr/sbin/nginx root        169      0  0 17:09 ?        00:00:00 ps -f  </code></WRAP>  |
 +| docker run --restart=always jenkinsci/jenkins                                                                     | Makes the container automatically restart after host restart.                                                                                                                                                                                                                                                                                                                                                                                                            |
 +| docker top <CONTAINERID>                                                                                          | Lists the containers running processes                                                                                                                                                                                                                                                                                                                                                                                                                                   |
 +| docker stats                                                                                                      | The resources consumed by docker                                                                                                                                                                                                                                                                                                                                                                                                                                         |
 +| docker container logs -f <CONTAINERID>                                                                            | logs from inside the conatainer                                                                                                                                                                                                                                                                                                                                                                                                                                          |
 +
 +
 +== Glossary ==
 +
 +|Docker-Machine| Daemon, which runs on a Linux Server |
 +|VirtualBox| Virtual Machine for Windows, Linux, ... Docker installs a small Linux in it. In this Linux Docker-Daemon runs Containers. |
 +|Docker-Daemon| Daemon, which runs on a Linux Server and executes containers (as separated processes) |
 +|Docker-Host-Host|<WRAP> 
 +  * Docker-aemon can only run in Linux
 +  * If you install Docker-Daemon on Windows/MaxOsX - a VirtualBoxVirtualMachine running a Linux in necessary, to install Docker-daemon inside it.
 +  * The Windows/MaxOsX Operating System, is then the Docker-Host-Host
 +
 +{{http://i520.photobucket.com/albums/w327/schajtan/2016-04-13_12-04-29_zpsuokvzupy.png}}
 +{{http://i520.photobucket.com/albums/w327/schajtan/2016-04-13_12-04-35_zpsm2wy99zz.png}}
 +
 +</WRAP>|
 +|Container-Host, Docker-Host, Docker-Daemon-Host| Linux, which runs the Docker-Daemon. If you installed Docker on your Laptop - the Linux running Docker-Daemon is the Container-Host. On Windows this is the Linux inside the VirtualBox Machine.  |
 +|Compose| Allows definition and instantiation of multi-container-applications. If Application requires multiple containers, e.g. for DB, AppServer, HttpHost containers have to know each other. Ips, ports etc.   |
 +|Kinematic| GUI for Container management. Can start new containers. Can stop, restart existing.|
 +|Notary|<WRAP> Service for signing and verification of docker images. 
 +  - upload your private key to Notary Server
 +  - sign your **docker image** with your **private key**
 +  - user of your docker-image will get your public-key/name from docker-image. \\ And be able to **contact notary-server to verify**, if some docker-image is signed by your (with your private-key)
 +</WRAP>|
 +|Swarm| Tool which allows to control multiple containers as one. To command a Swarm of Docker-Hosts - the same Interface is used, as for a single Docker-Host. Swarm distributes the Images then on multiple instances by different strategies. The commander doesn't know, that he commands multiple instances.|
 +|Dockerfile ||
 +
 +|Docker Hub||
 +|DUCP Docker Universal Control Plane||
 +|DDC Docker Data Center)||
 +|DTR Docker Trusted Registry||
 +
 +
 +
 +{{http://i520.photobucket.com/albums/w327/schajtan/2016-04-13_11-56-08_zpssgsnbzsl.png}}
 +
 +==== Setup on Windows ====
 +
 +=== Using Docker Desktop ===
 +The command & 'C:\Program Files\Docker\Docker\DockerCli.exe' -SwitchDaemon is a Windows command that starts the Docker daemon on a Windows system and registers it as a system service.
 +
 +<code>
 +& 'C:\Program Files\Docker\Docker\DockerCli.exe' -SwitchDaemon
 +</code>
 +
 +=== Running containers
 +
 +Example 
 +<code>
 +docker run -it --gpus all -p 8080:8080 -v $HOME/.tabby:/data tabbyml/tabby serve --model StarCoder-1B
 + --device cuda --chat-model Qwen2-1.5B-Instruct
 +</code>
 +
 +=== Using Windows native Hyper-V ===
 +
 +Achtung: currently there is a bug, which disabled Wireless Adapter, as soon as the Virtual Ethernet Switch is enabled in Hyper-V.
 +This means no WiFi may internet may be shared with a Hyper-V VM, which makes Hyper-V useless on Laptops.
 +
 +**This is why it is recommended using VirtualBox to install docker on Windows.**
 +
 +Hyper-V must be enabled in BIOS as following.
 +
 +<code>
 +Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V –All
 +
 +Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All
 +
 +</code>
 +
 +=== Using DOcker-Machine on Oracle VirtualBox ===
 +
 +
 +|<WRAP>
 +<fc #FF0000>Use **POWERSHELL**</fc> / CMD on Windows, to control docker. \\
 +On **Docker Quickstart Terminal** the container paths e.g. commands. \\
 +will be then resolved to windows like **/bash/sh.sh** to **D:/Programs/GitHub/bash/sh.sh** which will not work.
 +</WRAP>|
 +
 +
 +
 +Setting up docker is easy: use **Docker Toolbox** https://docs.docker.com/engine/installation/windows/
 +
 +**Configure Git Linux Shell**
 +Docker tools must be executed in a linux shell! \\
 +On Windows this shell is provided by Git. \\
 +Add **git.exe location**, **ssh.exe location** to your path:
 +<code>
 +C:\Program Files (x86)\Git\cmd
 +C:\Program Files (x86)\Git\bin
 +</code>
 +
 +**Start Linux Shell for docker:**
 +<code>
 +sh -li
 +</code>
 +
 +<fc #FF0000>All the further docker commands will be executed inside the linux shell, provided by git.</fc>
 +
 +== create a local docker-host named "my-default" ==
 +<code>
 +docker-machine create --driver virtualbox my-default
 +</code>
 +
 +
 +== switch to the new docker-host ==
 +In order to start / stop containers on new docker-host you have to modify environment variables, so that new host's ip etc. is saved there
 +
 +Go to e.g. powershell and type 
 +<code>
 +$ docker-machine.exe env --shell powershell my-default
 +
 +$Env:DOCKER_TLS_VERIFY = "1"
 +$Env:DOCKER_HOST = "tcp://192.168.99.101:2376"
 +$Env:DOCKER_CERT_PATH = "C:\Users\captain\.docker\machine\machines\dev"
 +$Env:DOCKER_MACHINE_NAME = "dev"
 +# Run this command to configure your shell:
 +# & docker-machine.exe env --shell powershell my-default | Invoke-Expression
 +</code>
 +
 +
 +At the bottom there is an instruction. follow it - type 
 +<code>
 +& docker-machine.exe env --shell powershell my-default | Invoke-Expression
 +</code>
 +
 +Now you are able to control docker-host "my-default"
 +
 +== Script the switching to docker-host ==
 +
 +It makes sence to write a script, to switch to other docker-hosts faster. \\
 +Here is a powershell script, which does the job
 +<code>
 +$arg1=$args[0]
 +
 +if($arg1 -ne $null){
 + docker-machine.exe env --shell powershell $name
 + & docker-machine.exe env --shell powershell $name | Invoke-Expression
 +}else{
 +  echo "usage: dockerhost <DOCKERHOSTNAME>"
 +}
 +</code>
 +
 +Store it e.g. under "C:\SCRIPTS\powershell\dockerhost.ps1" and call from powershell as \\
 +<code>
 +& "D:\1SCRIPTS\powershell\dockerhost.ps1" "my-default"
 +</code>
 +
 +
 +It is probably a good idea to add "D:\1SCRIPTS\powershell\" to the Path Environment-variable
 +
 +
 +
 +==== Exception when creating the docker host on Windows "VERR_INTNET_FLT_IF_NOT_FOUND" ====
 +
 +<code>
 +Error creating machine: Error in driver during machine creation: Unable to start the VM: C:\Program Files\Oracle\VirtualBox\VBoxManage.exe startvm default –type headless failed:
 +VBoxManage.exe: error: Failed to open/create the internal network ‘HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter #5’ (VERR_INTNET_FLT_IF_NOT_FOUND).
 +VBoxManage.exe: error: Failed to attach the network LUN (VERR_INTNET_FLT_IF_NOT_FOUND)
 +VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole
 +Details: 00:00:03.020271 Power up failed (vrc=VERR_INTNET_FLT_IF_NOT_FOUND, rc=E_FAIL (0X80004005))
 +<code>
 +
 +Fix
 +<code>
 +I  opened my Control Panel > Network & Internet > Network Connections and located my VirtualBox Host-Only Network adapter, called VirtualBox Host-Only Network #6 on my machine. I right-clicked it and selected the Properties, and checked the un-checked VirtualBox NDIS6 Bridged Networking Driver and started VirtualBox again.
 +</code>
 +
 +
 +==== install existing Container locally (DB, AppServer, HTTP daemon) ====
 +
 +Install existing container "hello-world"
 +<code>
 +docker run hello-world
 +</code>
 +
 +
 +Install JBoss via Kitematic \\
 +{{http://i520.photobucket.com/albums/w327/schajtan/2016-04-13_15-53-13_zpsscvgqrfv.png?400}}
 +
 +Install Apache container. There are many of them, I with that of user "bitnami"
 +<code>
 +docker pull bitnami/apache
 +docker run bitnami/apache
 +</code>
 +{{http://i520.photobucket.com/albums/w327/schajtan/2016-04-13_16-08-38_zpsawlhgtpu.png?400}}
 +
 +Checking from console whether containers are running is done via:
 +
 +Docker hosts?
 +<code>
 +docker-machine ls
 +</code>
 +
 +Docker images?
 +<code>
 +docker ps
 +</code>
 +
 +One Dockerhost "default" is running in virtualbox. \\
 +Two containers "apache" and "jboss" are running \\
 +{{http://i520.photobucket.com/albums/w327/schajtan/2016-04-13_16-14-31_zpsx99pjkma.png}}
 +
 +
 +==== Configure the container ====
 +
 +== Default configurations via KITEMATIC ==
 +
 +To start the container you can use KITEMATIC. \\
 +The default values will be used to start the container.
 +
 +The settings are listed as in form of environment variables:
 +
 +{{http://i520.photobucket.com/albums/w327/schajtan/2016-08-20_13-06-15_zpsxixxofao.png?600}}
 +
 +
 +== To retrieve configurations use "docker inspect" ==
 +
 +<code>
 +PS D:\> docker inspect f94c1c97220c
 +[
 +    {
 +        "Id": "f94c1c97220cca4ab391ccdf506b0443adebedaa6c091c364e3bd9a50c351b41",
 +        "Created": "2016-08-20T10:51:07.112560387Z",
 +        "Path": "/usr/local/bin/entrypoint.sh",
 +        "Args": [
 +            "slapd",
 +            "-d",
 +            "32768",
 +            "-u",
 +            "openldap",
 +            "-g",
 +            "openldap"
 +        ],
 +        "State": {
 +            "Status": "running",
 +            "Running": true,
 +            "Paused": false,
 +            "Restarting": false,
 +            "OOMKilled": false,
 +            "Dead": false,
 +            "Pid": 12232,
 +            "ExitCode": 0,
 +            "Error": "",
 +            "StartedAt": "2016-08-20T10:51:07.280067676Z",
 +            "FinishedAt": "0001-01-01T00:00:00Z"
 +        },
 +        "Image": "sha256:3ca16d1b31130d8e4c61e632ece7549aedf1c97065fa5f9e6051420910456c64",
 +        "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/f94c1c97220cca4ab391ccdf506b0443adebedaa6c091c364e3bd9a50c351b41/resolv.conf",
 +        "HostnamePath": "/mnt/sda1/var/lib/docker/containers/f94c1c97220cca4ab391ccdf506b0443adebedaa6c091c364e3bd9a50c351b41/hostname",
 +        "HostsPath": "/mnt/sda1/var/lib/docker/containers/f94c1c97220cca4ab391ccdf506b0443adebedaa6c091c364e3bd9a50c351b41/hosts",
 +        "LogPath": "/mnt/sda1/var/lib/docker/containers/f94c1c97220cca4ab391ccdf506b0443adebedaa6c091c364e3bd9a50c351b41/f94c1c97220cca4ab391ccdf506b0443adebedaa6c091c364e3bd9a50c351b41-json.log",
 +        "Name": "/adop-ldap",
 +        "RestartCount": 0,
 +        "Driver": "aufs",
 +        "MountLabel": "",
 +        "ProcessLabel": "",
 +        "AppArmorProfile": "",
 +        "ExecIDs": null,
 +        "HostConfig": {
 +            "Binds": null,
 +            "ContainerIDFile": "",
 +            "LogConfig": {
 +                "Type": "json-file",
 +                "Config": {}
 +            },
 +            "NetworkMode": "default",
 +            "PortBindings": {
 +                "389/tcp": [
 +                    {
 +                        "HostIp": "",
 +                        "HostPort": "389"
 +                    }
 +                ]
 +            },
 +            "RestartPolicy": {
 +                "Name": "no",
 +                "MaximumRetryCount": 0
 +            },
 +            "AutoRemove": false,
 +            "VolumeDriver": "",
 +            "VolumesFrom": null,
 +            "CapAdd": null,
 +            "CapDrop": null,
 +            "Dns": [],
 +            "DnsOptions": [],
 +            "DnsSearch": [],
 +            "ExtraHosts": null,
 +            "GroupAdd": null,
 +            "IpcMode": "",
 +            "Cgroup": "",
 +            "Links": null,
 +            "OomScoreAdj": 0,
 +            "PidMode": "",
 +            "Privileged": false,
 +            "PublishAllPorts": false,
 +            "ReadonlyRootfs": false,
 +            "SecurityOpt": null,
 +            "StorageOpt": null,
 +            "UTSMode": "",
 +            "UsernsMode": "",
 +            "ShmSize": 67108864,
 +            "ConsoleSize": [
 +                38,
 +                199
 +            ],
 +            "Isolation": "",
 +            "CpuShares": 0,
 +            "Memory": 0,
 +            "CgroupParent": "",
 +            "BlkioWeight": 0,
 +            "BlkioWeightDevice": null,
 +            "BlkioDeviceReadBps": null,
 +            "BlkioDeviceWriteBps": null,
 +            "BlkioDeviceReadIOps": null,
 +            "BlkioDeviceWriteIOps": null,
 +            "CpuPeriod": 0,
 +            "CpuQuota": 0,
 +            "CpusetCpus": "",
 +            "CpusetMems": "",
 +            "Devices": [],
 +            "DiskQuota": 0,
 +            "KernelMemory": 0,
 +            "MemoryReservation": 0,
 +            "MemorySwap": 0,
 +            "MemorySwappiness": -1,
 +            "OomKillDisable": false,
 +            "PidsLimit": 0,
 +            "Ulimits": null,
 +            "CpuCount": 0,
 +            "CpuPercent": 0,
 +            "BlkioIOps": 0,
 +            "BlkioBps": 0,
 +            "SandboxSize": 0
 +        },
 +        "GraphDriver": {
 +            "Name": "aufs",
 +            "Data": null
 +        },
 +        "Mounts": [
 +            {
 +                "Name": "a3aaab5b7f203b4e12273ce7e8abe36d84dac26edfaccb73dc84cba4ed7b6e75",
 +                "Source": "/mnt/sda1/var/lib/docker/volumes/a3aaab5b7f203b4e12273ce7e8abe36d84dac26edfaccb73dc84cba4ed7b6e75/_data",
 +                "Destination": "/etc/ldap",
 +                "Driver": "local",
 +                "Mode": "",
 +                "RW": true,
 +                "Propagation": ""
 +            },
 +            {
 +                "Name": "775a84ace393847a534da35847d76755f6dd5a00fd28fb32bb9b571e4ca14106",
 +                "Source": "/mnt/sda1/var/lib/docker/volumes/775a84ace393847a534da35847d76755f6dd5a00fd28fb32bb9b571e4ca14106/_data",
 +                "Destination": "/var/lib/ldap",
 +                "Driver": "local",
 +                "Mode": "",
 +                "RW": true,
 +                "Propagation": ""
 +            }
 +        ],
 +        "Config": {
 +            "Hostname": "f94c1c97220c",
 +            "Domainname": "",
 +            "User": "",
 +            "AttachStdin": false,
 +            "AttachStdout": false,
 +            "AttachStderr": false,
 +            "ExposedPorts": {
 +                "389/tcp": {}
 +            },
 +            "Tty": false,
 +            "OpenStdin": false,
 +            "StdinOnce": false,
 +            "Env": [
 +                "INITIAL_ADMIN_PASSWORD=Jpk66g63ZifGYIcShSGM",
 +                "GERRIT_PASSWORD=Jpk66g63ZifGYIcShSGM",
 +                "JENKINS_PASSWORD=Jpk66g63ZifGYIcShSGM",
 +                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
 +                "OPENLDAP_VERSION=2.4.40",
 +                "INITIAL_ADMIN_USER=admin.user",
 +                "SLAPD_PASSWORD=Jpk66g63ZifGYIcShSGM",
 +                "SLAPD_DOMAIN=ldap.example.com",
 +                "SLAPD_FULL_DOMAIN=dc=ldap,dc=example,dc=com"
 +            ],
 +            "Cmd": [
 +                "slapd",
 +                "-d",
 +                "32768",
 +                "-u",
 +                "openldap",
 +                "-g",
 +                "openldap"
 +            ],
 +            "Image": "accenture/adop-ldap:latest",
 +            "Volumes": {
 +                "/etc/ldap": {},
 +                "/var/lib/ldap": {}
 +            },
 +            "WorkingDir": "",
 +            "Entrypoint": [
 +                "/usr/local/bin/entrypoint.sh"
 +            ],
 +            "OnBuild": null,
 +            "Labels": {},
 +            "StopSignal": "15"
 +        },
 +        "NetworkSettings": {
 +            "Bridge": "",
 +            "SandboxID": "f27797636650a75dd59f4be114461210f16080c93ea033ed493e5d7b66822a7b",
 +            "HairpinMode": false,
 +            "LinkLocalIPv6Address": "",
 +            "LinkLocalIPv6PrefixLen": 0,
 +            "Ports": {
 +                "389/tcp": [
 +                    {
 +                        "HostIp": "0.0.0.0",
 +                        "HostPort": "389"
 +                    }
 +                ]
 +            },
 +            "SandboxKey": "/var/run/docker/netns/f27797636650",
 +            "SecondaryIPAddresses": null,
 +            "SecondaryIPv6Addresses": null,
 +            "EndpointID": "c06b1b0cbc96383532dc11ace95a87eb23d284080673c939d1754b0f2a1910ee",
 +            "Gateway": "172.17.0.1",
 +            "GlobalIPv6Address": "",
 +            "GlobalIPv6PrefixLen": 0,
 +            "IPAddress": "172.17.0.3",
 +            "IPPrefixLen": 16,
 +            "IPv6Gateway": "",
 +            "MacAddress": "02:42:ac:11:00:03",
 +            "Networks": {
 +                "bridge": {
 +                    "IPAMConfig": null,
 +                    "Links": null,
 +                    "Aliases": null,
 +                    "NetworkID": "c74769ec568289ae2be035acb672cc8272626d961e208861417420dffdbc2bc0",
 +                    "EndpointID": "c06b1b0cbc96383532dc11ace95a87eb23d284080673c939d1754b0f2a1910ee",
 +                    "Gateway": "172.17.0.1",
 +                    "IPAddress": "172.17.0.3",
 +                    "IPPrefixLen": 16,
 +                    "IPv6Gateway": "",
 +                    "GlobalIPv6Address": "",
 +                    "GlobalIPv6PrefixLen": 0,
 +                    "MacAddress": "02:42:ac:11:00:03"
 +                }
 +            }
 +        }
 +    }
 +]
 +</code>
 +
 +
 +The important parameters are "cmd" and "entrypoint". \\
 +Consider them, when running the container.
 +
 +<code>
 +# ldap 
 +docker run --name adop-ldap -d -p 389:389 --env INITIAL_ADMIN_PASSWORD="$passwordLdap" --env GERRIT_PASSWORD="$passwordLdap" --env JENKINS_PASSWORD="$passwordLdap" --entrypoint '/usr/local/bin/entrypoint.sh' accenture/adop-ldap:latest slapd -d 32768 -u openldap -g openldap
 +</code>
 +
 +
 +==== Container start ====
 +
 +Starting a self restarting (--restart=always), intractive (-ti), detached (-d) container.
 +<code>
 +docker run -p 8080:8080 -p 443:443 -t -d -i --restart=always --name jenkins jenkinsci/jenkins:2.65
 +</code>
 +
 +==== Entering the container interactively ====
 +
 +To start an interactive shell use the exec command. You can execute **bash** or **shell (sh)** depends on what is installed inside of the container.\\
 +The **-i** tells to start the last command interactively.\\
 +The **-t** tells to allocate a pseudo  terminal (tty). The pesudo-tty is used by docker to capture the output and show it to the docker-user.
 +
 +**-u 0** tells to start the command as user 0, which is root. Gives you the freedom to do everything inside it.
 +
 +<code>
 +docker exec -u 0 -it <CONTAINERNAME> bash
 +docker exec -u 0 -it <CONTAINERNAME> sh
 +</code>
 +
 +
 +
 +
 +==== Create a container with a service running in background ====
 +
 +This ais a short example about creating a long running container on an example of nginx:
 +
 +A container with installed nginx "schajtan/ubuntu-webserver:1.2" is required.
 +
 +Create file **startScript.sh**
 +<code>
 +#!/bin/bash
 +
 +# starts the nginx process
 +/etc/init.d/nginx start
 +
 +# keep the container alive by printing the nginx logs to STDOUT. Will be retrievable via "docker logs" command
 +tail -f /var/log/nginx/access.log
 +</code>
 +
 +
 +Create file **ubuntu-webserver-dockerfile.txt**
 +<code>
 +FROM schajtan/ubuntu-webserver:1.2
 +ADD startScript.sh /startScript.sh
 +ENTRYPOINT ["/startScript.sh"]
 +</code>
 +
 +
 +
 +  * Now execute the commands to **build** an image, 
 +  * **run** a long running container from the new image, 
 +  * show the **STDOUT** of the container
 +
 +
 +<code>
 +# builds the image from a dockerfile
 +docker build --tag schajtan/ubuntu-webserver:2.1 -f .\ubuntu-webserver-dockerfile.txt .
 +
 +# run a container, -P to redirect all exposed ports to random ports
 +docker run -P --name ubuntu3 schajtan/ubuntu-webserver:2.1
 +<CTRL + SHIFT + C> - exits the container
 +docker logs ubuntu3
 +</code>
 +
 +
 +
 +==== Backup ====
 +
 +
 +# stores the IMAGE. Attention: export import does not include the metadata of the image
 +<code>
 +docker save -o d:\Temp\containers\webserver-saved 0f20adbe8e90
 +docker load -i d:\Temp\containers\webserver-saved
 +</code>
 +
 +==== Monitoring ====
 +
 +To show the current ressource usage by container name use "stats"
 +<code>
 +docker stats $(docker ps --format '{{.Names}}') -a --no-stream > mystats.csv
 +</code>
 +
 +==== Logs within container ====
 +You can send the logs, happened within the container - to docker-service.
 +For that you need to log to STDOUT within the container.
 +
 +E.g. if you have a cron job - the output must be redirected as following:
 +<code>
 +07 2 * * * /data/docker/backup_webserver/backupscript.sh > /dev/stdout
 +</code>
 +
 +And from docker host you will be able to get the logs via
 +<code>
 +sudo docker logs <CONTAINER-NAME>
 +</code>
 +
 +
 +==== Host to Container connectivity ====
 +
 +There is a network-bridge between the host and containers.
 +You can reach the containers from the host.
 +
 +Docker offers different networking modes when running containers. Depending on the mode you choose you would connect to your MySQL database running on the docker host differently.
 +
 +
 +Docker creates a bridge named **docker0** by default. Both the docker host and the docker containers have an IP address on that bridge.
 +
 +== Host ==
 +on the Docker host, type **sudo ip addr** show docker0 you will have an output looking like:
 +<code>
 +[vagrant@docker:~] $ sudo ip addr show docker0
 +4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
 +    link/ether 56:84:7a:fe:97:99 brd ff:ff:ff:ff:ff:ff
 +    inet 172.17.42.1/16 scope global docker0
 +       valid_lft forever preferred_lft forever
 +    inet6 fe80::5484:7aff:fefe:9799/64 scope link
 +       valid_lft forever preferred_lft forever
 +</code>
 +
 +Here my host has the IP address **172.17.42.1**. 
 +
 +
 +== Container ==
 +INside the container do: **ip addr show eth0**. \\
 +Here it is 
 +<code>
 +root@e77f6a1b3740:/# ip addr show eth0
 +863: eth0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
 +    link/ether 66:32:13:f0:f1:e3 brd ff:ff:ff:ff:ff:ff
 +    inet 172.17.1.192/16 scope global eth0
 +       valid_lft forever preferred_lft forever
 +    inet6 fe80::6432:13ff:fef0:f1e3/64 scope link
 +       valid_lft forever preferred_lft forever
 +</code>
 +
 +Here my container has the IP address **172.17.1.192**. Now look at the routing table:
 +
 +<code>
 +root@e77f6a1b3740:/# route
 +Kernel IP routing table
 +Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
 +default         172.17.42.1     0.0.0.0         UG    0      0        0 eth0
 +172.17.0.0      *               255.255.0.0              0        0 eth0
 +</code>
 +
 +
 +So the IP Address of the docker host **172.17.42.1** is set as the default route and is accessible from your container.
 +
 +
 +==== Docker Context ====
 +The files/folders, which are in the same folder, like the Dockerfile - are packaged to a tar.gz and sent to the target machine with the docker daemon.
 +
 +See https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables---build-arg
 +
 +You can explicitly create a tar.gz package and reference it during the build command. \\
 +The tar ball has a flat hierarchy here, but may have any structure. Only, when referencing the files inside - one should consider this structure.
 +
 +The DockerFile is referenced explicitely inside the tar.gz ball (**-f ./Dockerfile.run.txt**)
 +<code>
 +# create the context tar.gz
 +tar -C /vagrant -cvf /tmp/runappcontext.tar.gz de.webapp.spring.one-0.0.1-SNAPSHOT.jar Dockerfile.run.txt
 +
 +# build the container with an existing gzipped context
 +docker build  --no-cache -t runapp -f ./Dockerfile.run.txt - < /tmp/runappcontext.tar.gz
 +
 +# run the container
 +docker run --name runAppContainer -d -p 8080:8080 runapp 
 +</code>
 +
 +
 +==== Start bash in container as root ====
 +If you would like to connect to the container MYCONTAINERNAME as root,
 +<code>
 +docker exec -it --user root MYCONTAINERNAME bash
 +<code>
 +
 +====== ADOP ======
 +
 +The Accenture ADOP stack is listed here: https://github.com/Accenture
 +
 +
 +The script to start the some relevant apps:
 +<code>
 +# run the code only in powershell / cmd - in GIT-Bash the paths, relative to container are resolved relative to the windows drive
 +
 +# to reproduce the default start via KITEMATIC us "docker inspect <CONTAINER>"
 +
 +
 +
 +$ip = "192.168.99.100"
 +$passwordLdap = "Jpk66g63ZifGYIcShSGM"
 +
 +
 +# ldap
 +docker run --name adop-ldap -d -p 389:389 --env INITIAL_ADMIN_PASSWORD="$passwordLdap" --env GERRIT_PASSWORD="$passwordLdap" --env JENKINS_PASSWORD="$passwordLdap" --entrypoint '/usr/local/bin/entrypoint.sh' accenture/adop-ldap:latest slapd -d 32768 -u openldap -g openldap
 +
 +
 +
 +
 +# ldap phpadmin. Login "cn=admin,dc=ldap,dc=example,dc=com". Pass "Jpk66g63ZifGYIcShSGM".
 +docker run --name=adop-ldap-phpadmin -d -p 32774:80 --env LDAP_SERVER_HOST="$ip" accenture/adop-ldap-phpadmin:latest '/run.sh'
 +</code>
 +
 +
 +====== Tools ======
 +TODO: add
 +http://www.midvision.com/blog/10-open-source-docker-tools-you-should-be-using
 +
 +^^^
 +|Docker||
 +|Rancher||
 +
 +
 +====== Debug ======
 +
 +=== Attach ===
 +
 +To find out, why the container is not starting - attach to it, to see what is happening in standard-out life:
 +
 +<code>
 +docker attach the-container-name
 +</code>
 +
 +It will display the error like:
 +
 +<code>
 +Error: parsing template /etc/sensu/templates/client.json.tmpl (template: client.json.tmpl:19: unexpected ".234" in operand)
 +</code>
 +
 +=== View stdout history ===
 +
 +STDOUT of process 1 is captured and stored on the host.
 +To see the Stdout history do:
 +
 +<code>
 +docker logs yourcontainername
 +</code>
 +
 +More: https://medium.com/@betz.mark/ten-tips-for-debugging-docker-containers-cde4da841a1d