botbotbot 's blog

Docker.io

Docker Support Only 64-bit System

docker-engine not docker.io anymore
docker.io is old name

Docker try it! - Interactive Tutorial

Install

Install on Debian

# Debian Jessie 8.0 (64-bit) or unstable packages
$ sudo apt-get update
$ sudo apt-get install docker-engine

Install on OSX - Homebrew-Cask

# if virtualbox not installed, install via homebrew cask
http://docs.docker.com/installation/mac/#from-your-shell

$ brew install caskroom/cask/brew-cask
$ brew cask install dockertoolbox

# start docker engine
$ docker-machine create
$ eval "$(docker-machine env default)"

Run Docker without sudo

#debian
$ sudo groupadd docker
$ sudo gpasswd -a ${USER} docker # or sudo adduser ${USER} docker
$ sudo service docker restart

Command Tips:

$ docker images --tree #list images in tree structure ('--tree' is deprecated)
$ docker ps -a #List all containers
$ docker ps -l #List lastest containers
$ docker ps -q #List containers display on IDs (quiet)

Command by yourself in containers - Working with Containers

$ docker run -i -t <image> /bin/bash

How to continue a docker which is exited

docker start `docker ps -q -l` # restart it in the background
docker attach `docker ps -q -l` # reattach the terminal & stdin

Clean Up - Remove Docker after exited

$ docker run --rm <imamge>

Docker: remove all Exited containers by Filippo Valsorda

$ sudo docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs sudo docker rm

Remove < none > images

# if space full in docker engine
$ docker rmi $(docker images | grep '<none>' | tr -s ' ' | cut -d ' ' -f 3)
# or
$ docker images -a | grep none | awk '{print $3}' | xargs docker rmi -f

Fix Repositoryalready being pulled

# $ dokcer pull <images>
# Fix Repository debian already being pulled by another client. Waiting.
$ sudo service docker restart

Mount directory to container - Managing data in containers

# docker run option
# -v, --volume=[] create a volume
# -v host:container mount host directory to container
#   ex. -v $PWD:/app , mount current path to /app in container
# -w, --workdir="" Working directory inside the container

$ docker run -v <host_dir_path>:<container_dir_path> -w <workdir_path> <image> <cmd>

Docker daemon on Debian: not start automatically - Bash Scripting: Wait for wireless connection, execute program

  1. write this script and add it into crontab ($ sudo crontab -e)
#!/bin/bash

Q="0"
while [ $Q = "0" ]; do
   Q=$(ping -c1 www.google.com 2> /dev/null | grep -c google);
done
echo Connected!

sudo service docker restart

Run multiple command in docker

$ docker exec <image> sh -c ‘<cmd>’
$ docker run <image> bash -c ‘<cmd>’

Crontab in Docker

Crontab with Docker enviorment - Sample Project

Dockerfile

# Docker env don't pass though cron jobs, you need to save env to file and load it in cron jobs.
# save Docker envoirment to file with command "env > <file>"

# To debug crontab see to run "rsyslogd" and see logs at "/var/log/syslo"
# CMD rsyslogd && && env > /root/env.sh && tail -f /var/log/cron.log

CMD cron && env > /root/env.sh && tail -f /var/log/cron.log

cron_task.sh

env - `cat /root/env.sh` $1

crontab

# always need ot >> to some where to avoid “(CRON) info (No MTA installed, discarding output)” error in the syslog
# http://askubuntu.com/questions/222512/cron-info-no-mta-installed-discarding-output-error-in-the-syslog

* * * * * root crontab_task.sh “<your command>" >> /var/log/cron.log 2>&1
#An empty line is required at the end of this file for a valid cron file.

docker Error: client and server don’t have same version

$ docker-machine upgrade <machine>

Set time zone in Dockerfile

$ echo "Asia/Bangkok" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata

Push docker to registry

$ docker login
# docker tag <image> <username/image:version>
$ docker tag viau10-app ibotdotout/viau10-app:latest
# docker push <username/image>
$ docker push ibotdotout/viau10-app

# private registry
$ docker tag <contrainer_id> <your_registry_domain>/<image>
$ docker push <your_registry_domain>/<image>

Force clean build of an image (without cache)

$ docker build --no-cache .

graphdriver prior storage driver “aufs” failed: invalid argument by @Kelindar

$ sudo rm -rf /var/lib/docker/aufs

To see the file size of your containers

$ docker ps -s

SSH to docker machine

# you can use `docker-machine ssh < machine > instead this
# 192.168.99.100 this is ip for < machine >
# that can check via `docker-machine ip < machine >
$ ssh docker@192.168.99.100
# password: tcuser

Fix No space left on device in default machine

# clean your mapping volume on host that was copied to docker machine
$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro -v /var/lib/

Install Docker-compose aka Fig

``sh $ apt-get update && apt-get upgrade -y $ apt-get install -y python-pip $ pip install -U docker-compose


### Docker-Compose Production

```sh
# https://docs.docker.com/compose/extends/
$ docker-compose -f production.yml

Dockerfile

  1. Dockerfile Reference
  2. Docker Explained: Using Dockerfiles to Automate Building of Images
  3. Dockerfile Best Practices
  4. Best practices for building secure Docker images
  5. Putting data in a volume in a Dockerfile
  6. Refactoring a Dockerfile for image size
  $ apt-get install -y --no-install-recommends <packages>

TDD for Dockerfile - ServerSpec

  1. TDD for Dockerfile by RSpec (severspec)

Dokcer Helper Tools::

  1. kitematic- Docker on Mac
  2. Dockviz - Visualizing Docker Data
  3. Vim Syntax for Dockerfile
  4. Squash docker images to make them smaller.

Reference::

  1. Docker User Guide
  2. Docker Benefits
  3. How to Manage your Docker Image
  4. 15 QUICK DOCKER TIPS
  5. Guidance for Docker Image Authors
  6. How We Run as a Non-Root Inside Docker Container
  7. Docker Command Line Doc
  8. MAKING DOCKER IMAGES SMALLER
  9. DOCKER DESKTOP - Github
  10. jenkins-docker-executors
  11. Clean up after Docker
  12. How to Use Docker on OS X: The Missing Guide
  13. introduction-to-docker
  14. docker-workflow-fig-sh
  15. Docker Exec Tutorial
  16. Awesome-docker
  17. Thai Docker Articles
  18. Deep Docker Articles by Micheal Crosby
  19. The Realities of Docker in Production
  20. Docker Toolbox - Migrate from Boot2Docker
  21. How to deploy PHP projects with docker
  22. Docker: 4 useful tips, you may not know about
  23. Microcontainers – Tiny, Portable Docker Containers
  24. Deep dive into Docker storage drivers
  25. Docker Cheat Sheet
  26. Docker-in-Docker
  27. Using Docker-in-Docker for your CI or testing environment? Think twice.
  28. How to scale Docker Containers with Docker-Compose
  29. Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
  30. Reduce Sending build context Size to Docker-Machine
  31. Docker : Storage Patterns for Persistence