MSSE SENG 5199

Course Materials for the MSSE Web Application Development Course

theme: Next, 3

Docker

MSSE 2017


Goals


What is Docker


How it works


Benefits


Running Docker


Components of Docker


Docker Engine


Images


Images include


Image properties


Image sizes


Starting a container from a given image


Example - Running a image

# docker run -ti ubuntu:latest ls

# docker run -ti ubuntu:latest bash


Containers


Container Commands


Container Naming


Container properties

docker run --rm -ti ubuntu sleep 5

Immutability in Docker


Docker flow


Commit example

# docker run -it ubuntu bash

//In container
# touch NEW_FILE
# exit
//Outside of container

//Commit the container with a new image name
# docker commit $NAME or $ID new-image

//List the new image
# docker images

Exposing ports


docker run -p 8081:8080 somecontainer


Let docker determine port


docker run -p 8080 somecontainer


Docker files


Docker file Commands


Couple more


Example - Spring Boot Docker File


FROM java:alpine
ADD build/libs/week-12-forms-0.0.1-SNAPSHOT.jar app.jar
RUN sh -c 'touch /app.jar'
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]


Creating the image

docker build -t msse/week12forms:1.0 .

Run the container

docker run --rm -ti -p 8080:8080 msse/week12forms:1.0


Attaching to a running container


Docker Networking

docker run --rm -ti --net=$NAME --name example-server <container>
docker run --rm -ti --net=$NAME --link example-server <container2> --name example-server2

Docker Compose


Docker Registry


Docker and the Cloud


Docker reference