Dockerizing your apps

Building Docker Images

app

image

containers

registry

Approaches

Imperative

Declarative

VM Like

Dockerfile

(manual)

(automated)

Imperative

registry

image

image

intermediate container

code

cp

build

commit

pull

run

push

  1. pull image
  2. run container 
  3. copy source code 
  4. build/compile
  5. commit
  6. push

Steps

dockerfile
FROM
RUN
COPY
EXPOSE
CMD
dockerfile
FROM
RUN
COPY
EXPOSE
CMD
docker build

image

http://hub.docker.com

sign up

Building Image for

PetClinic App

  • Spring boot application
  • Uses HSQLDB / MySQL as DB backend
https://github.com/devopsdemoapps/spring-petclinic

Two Step Process

  • Build step
  • Package Step

registry

maven

maven

build container

code

mount

build

artifact

pull

run

host

build step

registry

java

java

package container

artifact

cp

commit

pull

run

push

host

image

image

package step

registry

centos

install jdk

install mvn

mvn compile

mvn

mvn compile

selecting base image

lab

https://gist.github.com/initcron/61046646e5afcd1f0cb7fef9eebe2b75

Image creation instructions (Manual)

Dockerfile

Dockerfile

FROM java:8-jre-alpine

WORKDIR /

COPY target/spring-petclinic-*.jar app

EXPOSE 8080 

CMD java -jar app 

build

docker image build -t <dockrhub user id>/petclinic:v2 .

docker image ls 

dot (current directory)

test image

docker container run -idt --name pc <dockrhub user id>/petclinic:v2

docker container ls 

docker logs pc




tag as latest

docker image tag  <dockrhub user id>/petclinic:v2  <dockrhub user id>/petclinic:latest

docker image ls 

publish image to registry

docker image push <dockrhub user id>/petclinic:latest

docker image push <dockrhub user id>/petclinic
Made with Slides.com