Category Archives: docker

docker reset script – docker prune

I’m using docker for a lot of projects and have to switch context very often – I know – that kind of sucks, but that’s how it is…

Most containers can’t be shared between projects and I don’t want to spend more resources than necessary as my machines are on their limits. So I wrote a small bash script to get rid of all running containers, images, … on my local machine:

#!/bin/bash
echo "###########################"
echo "# clean docker"
echo "###########################"

echo "# stopping containers"
docker stop `docker ps | awk '{print $1}' | grep -v CONTAINER` >> /dev/null 2>&1

echo "# prune system"
docker system prune -f --volumes >> /dev/null 2>&1

echo "###########################"
echo "# done"

It will output a text like this

###########################
# clean docker
###########################
# stopping containers
# prune system
###########################
# done

when executed.

After that there shouldn’t be any leftovers except your images. If you also want to get rid of those you can run:

docker system prune -f --all --volumes

Or just add –all in the script above.

Attention: This will delete all your local volumes and images. So make sure you don’t run this if any data in the containers is of importance for you.

run kong with compose

Here a simple docker-compose.yml file to get kong community up and running. It is configured to use postgresql that persists data to a local docker volume. All ports are mapped to localhost only and log goes to stdout/stderr.

version: '3.4'
services:
  kong-db:
    image: 'postgres:10.1'
    ports:
      - 127.0.0.1:5432:5432
    environment:
      POSTGRES_USER: kong
      POSTGRES_PASSWORD: kong
      POSTGRES_DB: kong
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - db-volume:/var/lib/postgresql/data/pgdata
    healthcheck:
      test: 'echo "select 1" | psql -U kong kong || exit 1'
      interval: 1m
      timeout: 3s
      retries: 3
    restart: unless-stopped

  kong:
    image: 'kong:0.11.2'
    ports:
      - 127.0.0.1:8000:8000
      - 127.0.0.1:8443:8443
      - 127.0.0.1:8001:8001
      - 127.0.0.1:8444:8444
    environment:
      KONG_DATABASE: postgres
      KONG_PG_HOST: kong-db
      KONG_PG_DATABASE: kong
      KONG_PG_USER: kong
      KONG_PG_PASSWORD: kong
      KONG_PROXY_ACCESS_LOG: /dev/stdout
      KONG_ADMIN_ACCESS_LOG: /dev/stdout
      KONG_PROXY_ERROR_LOG: /dev/stderr
      KONG_ADMIN_ERROR_LOG: /dev/stderr
    links:
      - kong-db
# uncomment following line to run migrations for a new database
#    command: kong migrations up -v
    depends_on:
      - kong-db
    healthcheck:
      test: 'curl -f http://localhost:8001/status || exit 1'
      interval: 1m
      timeout: 3s
      retries: 3
    restart: unless-stopped

volumes:
  db-volume:

Attention: The kong container fails to start unless migrations are not run on the connected database. To do this simply uncomment the marked line and start the containers. With the command set the container will execute database migrations and stop with exit code 0. After that the line can be commented out again. Then you can start kong with the given file.

failed to run Kubelet: failed to create kubelet: misconfiguration: kubelet cgroup driver: “systemd” is different from docker cgroup driver: “cgroupfs”

Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial

Docker version 17.06.0-ce, build 02c1d87

openshift-origin-server-v3.6.0-c4dd4cf-linux-64bit

I followed the steps under https://docs.openshift.org/latest/getting_started/administrators.html#downloading-the-binary and got the error in the title. To fix this you have to add “–exec-opt native.cgroupdriver=systemd” to ExecStart of docker. The best way to do this is to add a addin file /etc/systemd/system/docker.service.d/override.conf with following content:

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// --exec-opt native.cgroupdriver=systemd

Then reload systemd and restart docker:

sudo systemctl daemon-reload
sudo systemctl restart docker