Skip to content

Latest commit

 

History

History
614 lines (495 loc) · 11.4 KB

slides.md

File metadata and controls

614 lines (495 loc) · 11.4 KB

!SLIDE

Docker - the catalyst of the DevOps Movement

Mark van Holsteijn - mvanholsteijn@xebia.com
Adé Mochtar - amochtar@xebia.com

**Slides** - [http://nauts.io/workshop-docker-introduction](http://nauts.io/workshop-docker-introduction)

!SUB

Docker has taken the world by Storm!

  • 400.000.000 downloads
  • 300.000+ Dockerized applications
  • 50.000+ third party projects on Github
  • 150.000.000 dollar in funding

!SUB

Why? It Supports True DevOps!

!SUB

Separation of Concerns

!SUB

Docker, the goodies

You get all the goodies of virtual machine per appliance, but without the cost.

  • Filesystem isolation
  • Resource isolation
  • Network isolation

And it is fast!

!SUB

What is Docker?

  • Container management for Linux
  • Abstraction for DevOps workflow
  • Adds images, image repository and version control to containers

!SUB

Basic Components

!SUB

Creating a Docker image

!SUB

Dockerfile

FROM stackbrew/ubuntu
RUN apt-get update && apt-get install -y apache2 && apt-get clean
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
EXPOSE 80
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]

!SUB

Docker Images

- contain everything needed to run the app - are portable across daemons - are built in layers - ordered to actions, Add file, Expose port, Run - stored in a Registry

!SUB

Docker Hub - Image Registry

- Contains Docker images - Public Registry with official images - Hosts your own private Registry

!SUB

Running a container

!SLIDE

Docker Image Layers

!SUB

Filesystems

Linux requires two filesystems

!SUB

Multiple rootfs

Docker supports multiple rootfs

!SUB

Docker Image

Read-only layers are called images

!SUB

Stacking images

Images can depend on other images, called parents

!SUB

Writable containers

On top of images docker creates writable containers

!SLIDE

Docker commands

  • Runtime
  • Information
  • Filesystem
  • Images
  • Repository

!SUB

Runtime

ps List containers
kill Kill a running container
restart Restart a running container
rm Remove a container
run Run a command in a new container
start Start a stopped container
stop Stop a running container
wait Block until a container stops, then print its exit code

!SUB

Information

info Display system-wide information
inspect Return low-level information on a container
logs Fetch the logs of a container
port Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
attach Attach to a running container

!SUB

Filesystems

insert Insert a file in an image
diff Inspect changes on a container's filesystem
commit Create a new image from a container's changes

!SUB

Images

build Build a container from a Dockerfile
import Create a new filesystem image from the contents of a tarball
export Stream the contents of a container as a tar archive
images List images
rmi Remove an image
history Show the history of an image

!SUB

Repository

login Register or Login to the docker registry server
pull Pull an image or a repository from the docker registry server
push Push an image or a repository to the docker registry server
search Search for an image in the docker index
tag Tag an image into a repository

!SLIDE

Dockerfile

Simple format

# Comment
INSTRUCTION arguments


See https://docs.docker.com/v1.8/reference/builder/

!SUB

Instructions

  • FROM
  • MAINTAINER
  • RUN
  • CMD
  • EXPOSE
  • ENTRYPOINT
  • ENV
  • ADD
  • VOLUME
  • USER
  • WORKDIR

!SUB

FROM

  • Syntax: FROM <image>[:<tag>]
  • Sets the base image for this image
  • FROM must be the first non-comment instruction in the Dockerfile.
  • Can appear multiple times to create multiple images

!SUB

RUN

  • Syntax: RUN <command>
  • Runs the specified command, and commits the result to the image
  • RUN can be used multiple times

!SUB

CMD

  • Syntax:
    • CMD ["executable","param1","param2"]
    • CMD ["param1","param2"], use with ENTRYPOINT
    • CMD command param1 param2
  • Provides defaults when executing a container
  • CMD can only be used one time

!SUB

ENTRYPOINT

  • Syntax:
    • ENTRYPOINT ["executable","param1","param2"]
    • ENTRYPOINT command param1 param2
  • Similar as CMD, but cannot be overwritten with command-line parameters
  • ENTRYPOINT can only be used one time

!SUB

EXPOSE

  • Syntax: EXPOSE <port> [<port> ...]
  • Defines which ports to expose

!SLIDE

Getting Started

Install your docker-machine on your machine

$ docker pull ubuntu
$ docker run ubuntu /bin/echo "hello world"

!SLIDE

Interactive containers

Start /bin/bash in a container

$ docker run -t -i ubuntu /bin/bash
root@e97c6f8d0013:/#

# look around all your processes
$ ps -ef

# Checkout your file system
$ ls

# and your network
$ ifconfig

# logout (container is stopped as /bin/bash exits)
$ exit

!SUB

detached containers

Running containers in the background

# run -d means detached detach
$ DOCKER_ID=$(docker run -d ubuntu \
bash -c 'while true ; \
	do sleep 1; \
	echo hello world at $(date); \
	done' )
$ echo $DOCKER_ID           # shows id of container
$ docker attach $DOCKER_ID  # attach to stdout of the container
$ docker ps 	      	    # shows all running containers
$ docker stop $DOCKER_ID    # stops specified container
$ docker ps -a 	      	    # shows stopped and running containers
$ docker rm $DOCKER_ID      # removes the container

!SLIDE

versioned file system

# Look at an empty filesystem
$ docker run ubuntu /bin/ls /tmp

# Modify the filesystem
$ DOCKER_ID=$(docker run -d ubuntu \
bash -c 'while true ; do \
		date > /tmp/$(date +%Y%m%d%H%M); \
		sleep 60;\
	done')

# See the changes on the filesystem
$ docker diff $DOCKER_ID
# Stop the instance
$ docker stop $DOCKER_ID ; docker rm $DOCKER_ID
# Changes are gone!
$ docker run ubuntu /bin/ls /tmp

!SLIDE

creating a new image

# Modify the filesystem
$ DOCKER_ID=$(docker run -d ubuntu \
bash -c 'while true ; do \
	date > /tmp/$(date +%Y%m%d%H%M); \
	sleep 60; \
     done' )

# See the changes on the filesystem and commit
$ docker diff $DOCKER_ID
$ docker commit $DOCKER_ID $USER/mydemo  # name of image $USER/mydemo

# Stop and remove the instance
$ docker stop $DOCKER_ID ; docker rm $DOCKER_ID

# Changes are persisted!
$ docker run $USER/mydemo /bin/ls /tmp

!SLIDE

Lab exercise

  • Create a tomcat7 image name $USER/tomcat7
  • push it to the Docker Hub registry
  • start 5 instances
  • show they are operational

!SUB

creating a tomcat image

Create a file 'Dockerfile' in the subdirectory tomcat7 with the following content.

FROM    tomcat

Build a new image

$ cd tomcat7
$ docker build -t $USER/tomcat7 .

!SUB

push to the registry

create an account on hub.docker.com

$ docker login
$ docker tag $USER/tomcat7 <docker-hub-name>/tomcat7:v0.1
$ docker push <docker-hub-name>/tomcat7:v0.1

!SUB

running tomcat

# Start a tomcat container
$ DOCKER_ID=$(docker run -P –d &lt;docker-hub-name>/tomcat7:v0.1)
# docker inspect show details about the container
$ docker inspect $DOCKER_ID
# Obtain mapped port of port 8080 of the container
$ PORT=$(docker port $DOCKER_ID 8080)
# access tomcat via mapped port
$ curl http://localhost:$PORT
# Obtain ip address of container
$ IPADDRESS=$(docker inspect inspect -f '{{.NetworkSettings.IPAddress}}' $DOCKER_ID)
# http request on image IP address
$ curl http://$IPADDRESS:8080

!SUB

creating a farm of tomcat

count=0
TOMCAT_IPS=""
while [ $count -lt 5 ] ; do
  DOCKER_ID=$(docker run -P –d &lt;docker-hub-name>/tomcat7:v0.1)
  IPADDRESS=$(docker inspect -f '{{.NetworkSettings.IPAddress}}' $DOCKER_ID)
  TOMCAT_IPS="$TOMCAT_IPS $IPADDRESS"
  count=$(($count + 1))
done
echo all tomcats : $TOMCAT_IPS

!SLIDE

Create a Docker image using Visual Studio

  • Install Docker for Visual Studio
  • Create a new .NET Core Web Application
  • Add Docker to the Web Project
  • Create a docker image from the bin\docker\app directory
  • Push the image to the registry
  • run your application as a container!

!SLIDE


[http://nauts.io/workshop-docker-introduction](http://nauts.io/workshop-docker-introduction)