Docker for OpenMRS

An environment for OpenMRS Atlas

OpenMRS

August 2014 / Alexis DUQUE / alexis.duque@openmrs.org

Summary


  1. Atlas presentation
  2. Docker introduction
  3. Docker Basics : work with containers
  4. Tutorial : Contribute using Atlas docker image
  5. Next Steps

OpenMRS Atlas

atlas.openmrs.org

A website on which members of the OpenMRS Community can register their site(s).


logo docker

Atlas environment

logo docker logo docker logo docker logo docker

logo docker logo docker logo docker


Apache HTTP, PHP 5.5, MySQL 5, phantomJS 1.9.7, Composer, Laravel4, OpenMRS ID, ...


Docker.io

logo docker

Why Docker ?


  • Find a way to easier deploy OpenMRS Atlas
  • Develop and hack Atlas everywhere
  • Easily distribute, share and get new contributors
  • Quickly test Atlas module across different OpenMRS version

Docker in few words


  • Develop, Ship an Run application
  • LXC Technology : unix isolation
  • Lighter than VM - Faster start

Docker Components


Docker Engine

Daemon, CLI, Local Index


Docker Hub

Image repository, Automated Builds, Versioning, Hooks.

Requirements and Installation

https://docs.docker.com/installation/#installation

Require Linux-specific features, but solution for others !


Lucky Ubuntu Users

curl -sSL https://get.docker.io/ubuntu/ | sudo sh

Windows/MacOS Users

Boot2Docker

Docker Basics

Work with images and containers

OpenMRS

Docker Pull

Pull your first OpenMRS image

docker pull openmrs/atlas:2.0-dev

Clone dev image from openmrs/atlas repo to your local repository

Docker Run

Create and run a container using an image

                 docker run [params] openmrs/atlas:2.0-dev

Lot of parameters - 3 modes :

  • Background
  • Foreground (default) : attach stdout/err
  • Interactive : attach stdin

Docker Run - Port

Port forwarding with the host

    docker run -P [host_port:container_port] openmrs/atlas:2.0-dev

Example : 8080 container port to 80 host port

    docker run -P 80:8080 openmrs/atlas:2.0-dev

80 host port shouldn't be used !

Docker Run - Volume

Shared host folder with the container

    docker run -v [host_folder:container_folder] openmrs/atlas:2.0-dev

Example : mount /opt/dev to /opt in the container

    docker run -v /opt/dev:/opt openmrs/atlas:2.0-dev

Absolute path is required !

Docker Run - Env variables

Define container environment variable


   docker run -e VAR_NAME=value  -e VAR_NAME2=value2 openmrs/atlas:2.0-dev


Example : define HOST_IP in the container

   docker run -e HOST_IP=127.0.0.1 openmrs/atlas:2.0-dev


Docker Run - Others

Others useful parameters

Define hostname inside the container

      docker run -h [hostname] openmrs/atlas:2.0-dev

Define container name (~ container id)

      docker run --name [container_name] openmrs/atlas:2.0-dev

Docker Stop/Start

Start and Stop a container (!= RUN )

Start a container from your local registry

     docker start [container_name] | ex: docker start atlas

Stop a running container

     docker stop [container_name] | ex: docker stop atlas

See what's happening


Show running container

     docker ps

Show images on your registry

     docker images

Clean UP :-)

Remove useless containers or images

Delete a single container or image (-f to force)

     docker rm -f [container_name] | ex: docker rm atlas 

     docker rmi [image_name] | ex: docker rmi openmrs/atlas:2.0-dev

Clean all containers and untagged images

     docker rm `docker ps --no-trunc -aq` 

     docker rmi $(sudo docker images -f "dangling=true" -q)

Get started !

HACK OpenMRS Atlas with Docker

OpenMRS Atlas

What's Next ?


Create an image using a Dockerfile

         docker built -t [image_name] path_to_dockerfile 


Use Docker for production

LEARN MORE

OpenMRS

https://docs.docker.com/userguide - https://blog.docker.com/

http://stackoverflow.com/search?q=docker

http://alexisduque.github.com/docker-presentation http://alexisduque.github.io/blog/2014/08/10/docker-for-developers