Friday, March 13, 2015

How to set up Shareable Docker Image for Adobe CQ/AEM

Use case

  • Large Set up time for developers
  • Inconsistent environments across all boxes
  • Flexible in container testing
  • No Single repository for whole system artifacts 

What is Docker

Docker is a platform for developers and sysadmins to develop, ship, and run applications. Docker lets you quickly assemble applications from components and eliminates the friction that can come when shipping code. Docker lets you get your code tested and deployed into production as fast as possible.
More information about Docker can be found here https://docs.docker.com/
Check Docker Cheat sheet: https://github.com/wsargent/docker-cheat-sheet

Set up

Docker requires two part to work,
  • Docker Hub or Docker registry (Where images are stored). You don't have to set up this part. We already have a private docker registry set up for you.
  • Docker client (To work with docker images). You need to install this in your local. Please check https://docs.docker.com/installation/ and based on your OS you need to install one. I have instruction to install it on Redhat Linux.

What would you get after following below instruction ?


  1. A Private Docker Hub, where you can manage AEM docker package. 
  2. A docker Image that will have author, publish and dispatcher instance.
  3. Steps to manage your docker hub and local image and make changes to them.

Assumption: I have docker registry set up for Red hat Linux. You might need different steps for different OS. I assume that on your OS mount you have a mount for /export. If this mount is not there then change paths in script.

Docker is only supported FOR RED HAT LINUX VERSION > 6.5 
(Use command cat /etc/*release to find your linux version)


Set Up Private Docker Registry


Prerequisite: 

If you are using redhat then 

Reference:

https://github.com/docker/docker-registry

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-private-docker-registry-on-ubuntu-14-04



Set Up docker Image using docker file


Once docker is install create a dummy directory and put your jar file, license file, Hotfix and other files in to it. More information about Docker file https://docs.docker.com/reference/builder/

Assumption:

1) You have AEM jar file
2) You have License File
3) You have your version of JDK
4) You have compiled HTTPD
5) They all are in same folder where Dockerfile is

For this create a file called Dockerfile and copy below. MAKE CHANGES BASED ON YOUR REQUIREMENT



Once Docker file is there build and create your private docker image using following command. This will create a shareable docker image


Once Docker registry is installed and you have shareable image, now you can install docker client on any other machine

Set up Docker Client

Prerequisite: Based on your OS please install docker client using https://docs.docker.com/installation/

Change default path if there is not enough space

Docker by default get installed under /var/lib/docker in Red Hat. Make sure that you have enough space there. If not then you have to do following.

Set Up docker for Non SSL version

By default Docker uses SSL to communicate to docker registry. If you do not have valid cert installed then you might need to do following


Set up local docker instance using docker client


Do following to start your local AEM instance using docker registry and docker client





How to update docker image

Please follow below step to update your docker image




Troubleshoot
Symptom: You are not able to access your instance from external machine
Solution: Try to restart your machine using 'reboot' for linux box and restart in mac
Symptom: Docker is not starting on mac
Solution: Make sure that you have localhost entry in /etc/hosts file. e.g. 127.0.0.1 localhost. then do following

boot2docker delete
boot2docker download
boot2docker init
boot2docker up
# End of this you will be asked to add some env variable in your ~/.bash_profile
# Open bash profile and add them

Symptom: Getting following error in mac
FATA[0032] An error occurred trying to connect: Get https://192.168.59.103:2376/v1.17/containers/json: dial tcp 192.168.59.103:2376: i/o timeout
Solution: http://cxwangyi.github.io/notes/2015-01-13-docker-pitfalls.html

boot2docker stop
boot2docker destroy
boot2docker init
boot2docker up
docker version

Symptom: On Mac local box not able to access instance using localhost:<port number> (https://docs.docker.com/installation/mac/)
Solution:



# Run following command
echo "$(boot2docker ip) localhost" | sudo tee -a /etc/hosts
# Then access your instance using localhost
# If you want to create other vhost then change above command with your vhost. For example
echo "$(boot2docker ip) localhost.wemblog.com" | sudo tee -a /etc/hosts



Some use full docker command



Upload content


You can use Recap tool http://adamcin.net/net.adamcin.recap/ to install content once image is set up. You can even put this recap tool as part of your image when you are creating docker image. Just put them under install folder. 

Note that every time you update your image, Uploaded content or local changes might get overriden. You have to commit your changes using docker commit and then apply update on top of that and then share your image.

Useful resource: http://www.techinsight.io/review/adobe-experience-manager/incontainer-testing-for-aem-with-docker/

Note: As usual let me know if you have any question.