Wednesday, 26 April 2017

Install Docker and Build Docker Image for Java Services


Overview
This page captures high level info to install docker and to build and deploy applications on docker

Steps

Install Docker

  1. Install docker 
    • For mac from the link https://docs.docker.com/docker-for-mac/install/#install-and-run-docker-for-mac
    • For windows from the link https://docs.docker.com/docker-for-windows/install/
  2. Once Docker is installed, you can run some basic commands from the following link
    • https://docs.docker.com/docker-for-mac/
  3. Docker basics tutorial
    • https://docs.docker.com/engine/getstarted/
Build Docker Image for Java Web Services

There are multiple ways to build a docker image at multiple levels of integration. Following are the high level steps for building a docker image from war file.

  1. Create "Dockerfile" for guiding docker through the build process
    • Create a file with name "Dockerfile"
    • Add the webserver image to the Dockerfile, that you want to deploy your application as the base, as follows
      • FROM tomcat:7-jre8
    • Add maintainer name
      • MAINTAINER "your mailid"
    • Add copy command to the deploy path
      • ADD {warfile-name} /usr/local/tomcat/webapps/
    • Complete Dockerfile (sample)
      • #Pull base image
      • From tomcat:7-jre8
      • # Maintainer
      • MAINTAINER "dixitsatish34@gmail.com"
      • # Copy to images tomcat path
      • ADD ranking-service.war /usr/local/tomcat/webapps/
  2. Copy Dockerfile and war file to a directory
  3. Run the following command for Docker build
    • docker build -t {image-name} .
    • ex: docker build -t ranking-service .

Deploy & Run Docker Image

Use the following command to run the image build in previous step(with port bindings)

    • docker run --rm -it -p {port binding} {image-name}
    • ex: docker run --rm -it -p 8080:8080 ranking-service


References
https://docs.docker.com/docker-for-mac/install/

Enjoy Learning.

No comments:

Post a Comment