Changes between Version 20 and Version 21 of SystemAdministration/Docker


Ignore:
Timestamp:
05/04/16 14:54:24 (8 years ago)
Author:
Sander Maijers
Comment:

add tip about renaming running containers

Legend:

Unmodified
Added
Removed
Modified
  • SystemAdministration/Docker

    v20 v21  
    11[[PageOutline]]
     2
    23= Docker =
    3 
    44If possible we aim to dockerize (containerize, virtualize) the applications. The main advantage of this approach is that we can provide identical environments across servers, including development, staging and production.
    55
    66We regularly have Docker meetings to discuss open issues, and transform them into policies.
    77
    8 # Best practices (external) #
    9 http://developerblog.redhat.com/2016/02/24/10-things-to-avoid-in-docker-containers/
     8# Best practices (external) # http://developerblog.redhat.com/2016/02/24/10-things-to-avoid-in-docker-containers/
    109
    1110# Open issues #
    1211
    13 1. How to build containers?
    14 1. Where to store application and container configuration/build information, and how?
    15 1. Should we maintain our own Docker Registry?
    16 1. How do we manage logging from within containers?
    17 1. Which Linux distro for containers? Security aspects?
    18 1. Backup strategy? Disk quota?
    19 1. ...
     12 1. How to build containers? Packer vs. Dockerfile?
     13 1. Where to store application and container configuration/build information, and how?
     14 1. Should we maintain our own Docker Registry?
     15 1. How do we manage logging from within containers?
     16 1. Which Linux distro for containers? Security aspects? Alpine Linux v. other?
     17 1. Backup strategy? Disk quota? Snapshots, tarballs within container, etc.?
     18 1. ...
    2019
    2120# Policies #
     21
    2222## Building images ##
    2323
    2424### Layering inheritance ###
    25 * One base image. If possible, this image is both a demo and production image.
    26 * If not possible: separate demo and production images that inherit from the base image.
    27 
    28 ### Packer ###
    29 ...
     25
     26 * One base image. If possible, this image is both a demo and production image.
     27 * If not possible: separate demo and production images that inherit from the base image.
     28
     29### Packer ### ...
    3030
    3131### Git ###
    3232
    33 ...
     33 1. Repo naming?
     34 1. Dependencies on other images?
    3435
    3536### Application packaging ###
    36 * We will always use [https://github.com/Yelp/dumb-init dumb-init] as the entry point process inside containers.
     37
     38 * We will always use [https://github.com/Yelp/dumb-init dumb-init] as the entry point process inside containers.
     39
     40## Deploying into containers
     41
     421. `docker rename` existing and possibly running containers, volumes, networks, etc.
     431. Create containers.
     441. `docker stop old_container && docker start new_container`.
    3745
    3846## Data ##
    3947
    4048||= Kind of data =||= How to use it with Docker =||
    41 ||Variable data on which app configuration does not directly depend||on volume per content set||
    42 ||Application configuration||within image of application||
    43 ||Global configuration (used by more than one container)||on volume per type of configuration||
    44 ||Secrets (passwords, private key files)||on isolated volume (exactly the same across hypervisors)||
     49|| Variable data on which app configuration does not directly depend || on volume per content set ||
     50|| Application configuration || within image of application ||
     51|| Global configuration (used by more than one container) || on volume per type of configuration ||
     52|| Secrets (passwords, private key files) || on isolated volume (exactly the same across hypervisors) ||
    4553
    4654### Backup data in a container ###
     
    4957
    5058General command:
     59
    5160{{{
    5261#!sh
     
    5463docker run -ti --rm --volumes-from <container_name> -v <host directory>:<container directory> ubuntu <backup command>
    5564}}}
    56 
    5765Examples:
     66
    5867{{{
    5968#!sh
     
    6877docker run -ti --rm --volumes-from nginx_volume -v /scratch:/backup ubuntu tar -pczvf /backup/nginx_data.tgz /etc/nginx /usr/share/nginx/html /var/log/nginx
    6978}}}
    70 
    7179### Restore data in a container ###
    72 ## Naming ##
    73 '''Volumes''':
     80
     81## Naming
     82
     83## '''Volumes''': ... '''Volume containers''': ... '''Containers''': ... '''Images''': ... '''Git repositories''':
     84
     85## Managing containers ##
     86
     87 * Willem has worked on creating shell scripts to manage Docker containers based on images and Dockerfiles.
     88 * Sander has worked on creating shell scripts to manage Docker containers based on Packerfiles.
     89
     90Listing running containers:
     91
     92{{{
     93#!sh
     94
     95docker ps
     96}}}
     97Listing all (including stopped) containers:
     98
     99{{{
     100#!sh
     101
     102docker ps -a
     103}}}
     104Starting, stopping and restarting containers:
     105
     106{{{
     107#!sh
     108
     109docker [start|stop|restart] <container_name>
     110}}}
     111Connecting to a container to e.g. look at log files or modify configuration:
     112
     113{{{
     114#!sh
     115
     116docker exec -ti <container_name> /bin/bash
     117}}}
     118Tailing the container output:
     119
     120{{{
     121#!sh
     122
     123docker logs -f --tail=100 <container_name>
     124}}}
     125Kill all running containers:
     126
     127{{{
     128#!sh
     129
     130docker kill $(docker ps -q)
     131}}}
     132## Managing images ##
     133
     134Listing all images:
     135
     136{{{
     137#!sh
     138
     139docker images
     140}}}
     141Cleaning up unused (untagged/dangling) images:
     142
     143{{{
     144#!sh
     145
     146docker rmi $(docker images -q -f dangling=true)
     147}}}
     148## Docker registry at https://docker.clarin.eu/ ##
     149
    74150...
    75 '''Volume containers''':
    76 ...
    77 '''Containers''':
    78 ...
    79 '''Images''':
    80 ...
    81 '''Git repositories''':
    82 
    83 ## Managing containers ##
    84 
    85 * Willem has worked on creating shell scripts to manage Docker containers based on images and Dockerfiles.
    86 * Sander has worked on creating shell scripts to manage Docker containers based on Packerfiles.
    87 
    88 Listing running containers:
    89 {{{
    90 #!sh
    91 
    92 docker ps
    93 }}}
    94 
    95 Listing all (including stopped) containers:
    96 {{{
    97 #!sh
    98 
    99 docker ps -a
    100 }}}
    101 
    102 Starting, stopping and restarting containers:
    103 {{{
    104 #!sh
    105 
    106 docker [start|stop|restart] <container_name>
    107 }}}
    108 
    109 Connecting to a container to e.g. look at log files or modify configuration:
    110 {{{
    111 #!sh
    112 
    113 docker exec -ti <container_name> /bin/bash
    114 }}}
    115 
    116 Tailing the container output:
    117 {{{
    118 #!sh
    119 
    120 docker logs -f --tail=100 <container_name>
    121 }}}
    122 
    123 Kill all running containers:
    124 {{{
    125 #!sh
    126 
    127 docker kill $(docker ps -q)
    128 }}}
    129 
    130 ## Managing images ##
    131 
    132 Listing all images:
    133 {{{
    134 #!sh
    135 
    136 docker images
    137 }}}
    138 
    139 Cleaning up unused (untagged/dangling) images:
    140 {{{
    141 #!sh
    142 
    143 docker rmi $(docker images -q -f dangling=true)
    144 }}}
    145 
    146 ## Docker registry at https://docker.clarin.eu/ ##
    147 
    148 ...
    149 
    150 
    151151
    152152# Dockerized applications #
     
    178178docker logs registry
    179179}}}
    180 
    181180### Past issues ###
    182181
    183182After moving the clarin docker registry from `stoor146` to `clarinvm` and following the above instructions, we ran into the following error when starting the registry container:
     183
    184184{{{
    185185OSError: [Errno 2] No such file or directory: './registry._setup_database.lock'
    186186}}}
    187 
    188187As documented in [https://github.com/docker/docker-registry/issues/892 #892], adding the `-e GUNICORN_OPTS=["--preload"]` resolved the issue
    189188
     
    214213docker logs nexus
    215214}}}
    216 
    217215## NGinx proxy ##
    218216
     
    241239docker logs nginx
    242240}}}
    243 
    244241# References #
    245242
    246 * Docker volumes
    247   * https://medium.com/@ramangupta/why-docker-data-containers-are-good-589b3c6c749e
    248 * Docker Application configuration
    249   * https://dantehranian.wordpress.com/2015/03/25/how-should-i-get-application-configuration-into-my-docker-containers/
    250 * Docker containers and images visually explained:
    251   * http://merrigrove.blogspot.nl/2015/10/visualizing-docker-containers-and-images.html
     243 * Docker volumes
     244   * https://medium.com/@ramangupta/why-docker-data-containers-are-good-589b3c6c749e
     245 * Docker Application configuration
     246   * https://dantehranian.wordpress.com/2015/03/25/how-should-i-get-application-configuration-into-my-docker-containers/
     247 * Docker containers and images visually explained:
     248   * http://merrigrove.blogspot.nl/2015/10/visualizing-docker-containers-and-images.html