Docker

Installation
https://docs.docker.com/install/linux/docker-ce/ubuntu/#set-up-the-repository
http://www.panticz.de/install-docker

Add user to docker group
sudo usermod -aG docker $USER
su - $USER

systemctl enable docker
systemctl status docker

# Delete all containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

# Delete all images
docker rmi $(docker images -aq) -f

# fix missing btrf storage driver
sudo rm -rf /var/lib/docker/aufs

Debug / Run test container
docker info
docker run hello-world
#docker run -it centos bash
docker run -it ubuntu

Login to container
docker exec -it CONTAINER_ID bash

#docker run -i --rm ubuntu bash

sudo docker run -i -t --name dc-ubuntu ubuntu bash
sudo docker start -i dc-ubuntu

# wordpress
docker run -d --name dc-mysql -e MYSQL_ROOT_PASSWORD=mysqlpwd mysql
docker run -d --name dc-wordpress --link dc-mysql:mysql -p 7894:80 wordpress

# search
docker search icinga
docker search --filter is-official=true ubuntu
docker pull phre/icinga

docker run --name dc-nginx -d -p 7890:80 nginx
http://localhost:7890/
docker logs dc-nginx

# images
sudo docker images
sudo docker rmi 3eXXXXx

apt-get install docker
docker run -t -i --rm ubuntu bash
docker run -i -t --name dc-ubuntu ubuntu bash
docker start -i dc-ubuntu
docker run --name dc-nginx -d -p 7890:80 nginx
docker logs dc-nginx
docker stop dc-nginx
docker rm dc-nginx
docker run --name dc-nginx -d -p 7890:80 -v /tmp/srv/:/usr/local/nginx/html:ro nginx
docker run --name dc-nginx-tmp -t -i nginx /bin/bash
docker commit dc-nginx-tmp img-mynginx
docker run --name dc-mynginx -d -p 7891:80 img-mynginx nginx

# view all cointainer (also inactive)
docker ps -a

# remove all container
docker ps -qa | xargs docker rm

/tmp/dbuildtst/Dockerfile
MAINTAINER Mein Name
FROM nginx
RUN echo 'Hello again! ' > /usr/local/nginx/html/index.html

docker build -t=img-mynginx2 /tmp/dbuildtst/

docker run --name dc-mynginx2 -d -p 7892:80 img-mynginx2

Registry
http://registry.hub.docker.com

# generate auth configuration for private remote docker repository
docker login registry.example.com -u user -p pass

AUTH=$(echo -n username:password | base64)

# auto login
# ~/.docker/config.json
{
"auths": {
"registry.example.com": {
"auth": "$AUTH"
}
},
"HttpHeaders": {
"User-Agent": "Docker-Client/18.12.3-ce (linux)"
}
}

docker login registry.example.com

https://wiki.debian.org/Docker

Run Docker inside LXC container
# http://stackoverflow.com/questions/22085657/can-docker-run-inside-a-linux-container
echo 'DOCKER_OPTS="--exec-driver=lxc"' | tee -a /etc/default/docker
service docker restart

# mysql container
sudo docker pull mysql

# build a container
https://www.digitalocean.com/community/tutorials/docker-explained-using-dockerfiles-to-automate-building-of-images

# notes
docker run --lxc-conf="lxc.network.hwaddr=92:20:de:b0:6b:61" my_image ifconfig
edit /etc/default/docker: DOCKER_OPTS="--dns 8.8.8.8 -e lxc"
apt-get install lxc (lxc-docker is not enough)
docker run --lxc-conf="lxc.network.hwaddr=92:20:de:b0:6b:61" -t myimage

# non root?
https://docs.docker.com/installation/debian/

# quick & easy install
wget -qO- https://get.docker.com/ | sh

# docker under LXC
http://ashish1099.github.io/blog/2015/05/23/docker-inside-lxc/
https://www.stgraber.org/2016/04/13/lxd-2-0-docker-in-lxd-712/
cat /var/lib/lxc/docker/config
...
lxc.aa_profile = unconfined
lxc.cgroup.devices.allow = a
lxc.cap.drop =

# 15 Quick Docker Tips
http://www.centurylinklabs.com/15-quick-docker-tips/

# get volume information
for VOLUME in $(docker volume ls -q); do
docker volume inspect ${VOLUME}
done

# delete unused volumes
docker volume rm $(docker volume ls -qf dangling=true)

# service
/usr/lib/systemd/system/docker.service
/etc/systemd/system/multi-user.target.wants/docker.service

Links
https://github.com/panticz/installit/blob/master/install.docker.sh
https://docs.docker.com/engine/reference/commandline/dockerd/

Docker Machine
https://docs.docker.com/machine/install-machine/

Docker Compose
https://docs.docker.com/compose/install/

List content of docker repository
DOCKER_REPOSITORY_IP=10.0.11.7
curl -X GET http://${DOCKER_REPOSITORY_IP}:5000/v2/_catalog | python -m json.tool

Create profile with connection to VLAN
lxc profile copy default mgmt-dev
# lxc profile list
lxc profile device set mgmt-dev eth0 nictype macvlan
lxc profile device set mgmt-dev eth0 parent mgmt-dev-v1234
lxc profile show mgmt-dev

Configure HTTPS proxy
https://docs.docker.com/config/daemon/systemd/#httphttps-proxy
# configure https proxy
cat < /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
#Environment="HTTP_PROXY=https://:@:"
Environment="HTTPS_PROXY=https://:@:"
EOF

systemctl daemon-reload
systemctl restart docker

# find restarting nodes
docker ps -a --filter status=exited --filter status=restarting

# output format
docker images --format '{{.Repository}}:{{.Tag}}'
docker images --format '{{.Size}}\t{{.Repository}}\t{{.Tag}}\t{{.ID}}'

Get registry packages
DOCKER_REPOSITORY_IP=https://registry.example.com
curl -X GET ${DOCKER_REPOSITORY_IP}/v2/_catalog | python -m json.tool

DOCKER_CONTAINER=foo/bar
curl -X GET ${DOCKER_REPOSITORY_IP}/v2/${DOCKER_CONTAINER}/tags/list | python -m json.tool

Network
Macvlan network driver
https://docs.docker.com/v17.09/engine/userguide/networking/get-started-macvlan/

Disk usage
docker system df -v

DOCKER_CONTAINER=kolla/ubuntu-source-base
curl -X GET http://${DOCKER_REPOSITORY_IP}:5000/v2/${DOCKER_CONTAINER}/tags/list | python -m json.tool