Install debian

install latest version on debian
https://docs.docker.com/engine/installation/linux/ubuntulinux/

Windows

Boot2Docker
https://github.com/boot2docker/windows-installer/releases
https://github.com/boot2docker/osx-installer/releases
Docker daemon draait niet op windows en osx, mbv boot2docker, die een vm installeert op virtualbox, wordt docker op je machine geinstalleerd.
Voor windows bestaat er ook een optie om msysgit te installeren, dit is een alternatief voor de wndows cmd terminal.


Om docker commando's te kunnen uitvoeren zonder het sudo commando, moet uw gebruiker worden toegevoegd aan de docker group:

hierdoor wordt het voltooien van docker commando's met de tab toets ook mogelijk.
Op sommige distributies bestaat de docker groep niet, maak hem in dat geval aan met

Realiseer je dat gebruikers in de docker groep in principe root toegang hebben.

uitloggen en opnieuw inloggen voor het resultaat images are specified by repository:tag

image wordt aangeroepen met repository:tag,

Find your container

docker ps to list running containers -a flag to list all containers

Container with Terminal

Gebruik de -i en -t flag met docker
-i flag verteld docker te verbinden met STDIN van de container,
-t flag specificeerd de pseudo-terminal
Je dient het terminal proces als commamndo mee te geven (bash)

Exit the Terminal

Exit om de terminal af te sluiten en terug te keren naar de host terminal, dit sluit de container
Om uit de terminal te stappen zonder de container te sluiten Docker ps command

docker ps -q #om alleen het container ID te laten zien

docker ps -l #om de laatste container die is gestart te laten zien

docker ps -aq #all containers with only their short ID

docker ps -lq #list the short ID van de laatst gestarte container

docker ps -a --filter "exited-1" #past een filter toe op exit code 1 (exit with error), momenteel kan er worden gefiltert op exit-code en status ( restarting, running, exited and paused)


Running in detached mode, wordt ook wel op de achtergrond genoemd of als een daemon -d flag, om de output te bekijken gebruik je: maak een centos container en voor het ping commando 50 keer uit Met de -P flag wordt de container port gemapped met de host port

attach en detach

hier loop je het risico de container af te sluiten door per ongeluk op crtl C te drukken vb, of naam, verlaat de container met Crtl + P + Q

docker exec

commando wordt gebrukt om extra processen in de container te starten als men deze terminal (bash) afsluit blijft de container draaien.

docker logs bekijken

-f optie als tail -f to exit

Stopping a container

, sends a SIGTERM to the main container proces, proces then receives a SIGKILL after a grace period, -t flag grace period can be specified , sends SIGKILL immediately to mail container proces

Restart a container

docker start to restart a container that has been stopped, the container will start using the same options and command specified previously. Can attach to the container with the -a flag

Formatting docker inspect output

Deleting containers

Delete all containers that are stopped Use dockers ps -aq to list id's of all containers, feed the output to docker rm

List all stopped containers

delete the latest container that was run

Comparing containes with docker diff

Methoden om images te bouwen

1. commit changes from a container as a new image allows you to build images interactively get terminal access inside a container and instal the necessary pograms and your application then save the container as a new image using the docker commit command

2. build from Dockerfile

create a Dockerfile in een nieuwe map of in een bestaande applicatie map Schrijf de instructies om het image te bouwen (what program to install, what base image to use, what command to run) Build examples #comment in een build file FROM ubuntu:14.04 of FROM johnytu/myapplicaiton:1.0 of FROM company.registry:5000/myapplication:1.0 RUN apt-get install vim RUN apt-get install curl draai docker build commando of het image te bouwen van het Dockerfilesd # Build an image use the current folder as context path. # as above but use the project folder as context path 3. Import a tarbal into Docker as a standalone base layer

Docker uses exact strins in your Dockerfile to compare with the cache, simply changing the order of instructions will invalidate the cache. To disable the cache manually use: --no-cache flag

Run instruction aggregation

h Can aggregate multiple RUN instructions by using && Commands will all be run in the same container and committed as a new image at the end Reduces the number of image layers that are produced.

Docker history

command shows us the layers that make up an image

CMD instruction

CMD defines a default command to execute when a container is created Shell format and EXEC format Can only be specified once in a Dockerfile, if specified multiple times the last CMD instruction is executed

ENTRYPOINT instruction

Defines the command that wil be run when a container is excuted Run time arguments and CMD instructions are passed as parameters to the ENTRYPOINT instruction Container essentially runs as an executable shell vs exec format In shell form, the command will run inside a shell with /bin/sh -c Exec format allows execution of command in images that don't have /bin/sh Shell form is easier to write and you can perform shell parsing of variables Exec form does not require image to have a shell For ENTRYPOINT instructions, using shell form will prevent the ability to specify arguments at run time - The CMD argument will not be used as parameters for ENTRYPOINT Overriding ENTRYPOINT To override teh command specified by ENTRYPOINT, use the --entrypoint flag, Useful for troubleshooting your images

COPY instruction

h The copy instruction copies new files or directories from a specified source and adds them to the container filesystem at a specified place. The

path must be inside the build context, if the <> path is a directory, all files in de directory are copied, the directory itself is not copied. You can specify multiple