Download presentation
Presentation is loading. Please wait.
1
Iterating Faster with Docker + Cascade
John David Garza Cascade User Conference • October 2017
2
Introduction Who am I? What do I do? Cascade Users since 2014
The University of Texas at San Antonio What do I do? Joined 2015 University Webmaster Communications and Marketing Cascade Users since 2014 University is very decentralized Lots of environments Lots of websites
3
Show & Tell Demo Local Development Docker + Cascade Docker + Lucee
Smaller contexts Docker + Lucee Replicating existing sites/infrastructure Docker + Wordpress Over 25% of the web! Switch to safari and show currently running containers Lucee for coldfusion development Local alerts development Docker cascade Mailcatcher?
4
Today’s Agenda Introduction Show and Tell Demo (why docker)
Prerequisites What is Docker and Why Use It Learn by Example Demo 1 – beginner (tomcat + docker) Demo 2 – intermediate (mysql + docker) Demo 3 – advanced (cascade + docker) Wrap-Up/More Resources
5
Prerequisites This talk will be technical heavy Familiar with Linux?
Server Administration? Comfortable with the command line? Familiar with Java application servers (tomcat) Have you ever installed/configured cascade? Code for this presentation is available on bitbucket (git) prerequisites this talk will be technical heavy familiar with server administration? VMs? (This will help with understanding the concepts) familiar with linux? ++ (1 shell script, several configuration files) comfortable with the command line? ++ (demos are in git and easily accessible with a text reader) familiar with standard relational databases? (oracle, mysql, mssql) familiar with configuring java application servers? (wildfly, tomcat) have you ever deployed cascade? +++ i'll be demoing with this mac, but steps should be easily reproducible on a windows pc and linux pc what is docker? [docker vs VM image] [ "software container platform" "Docker automates the repetitive tasks of setting up and configuring development environments"
6
Docker: What is it? “lightweight VMs”
what-docker “Docker automates the repetitive tasks of setting up and configuring development environments” Docker > Containers > Images what is docker? [docker vs VM image] [ "software container platform" "Docker automates the repetitive tasks of setting up and configuring development environments” I like using the paraphrase: "lightweight VM" Docker has it roots in cgroups and LinuX Container (LXC) which started back in 2008 2013 Docker emerged as container management tool which used LXC to implement containers Containers are described by a Dockerfile, this file tells docker how to build a container, what files are needed, what packages may need to be installed, etc. Docker utilizes a Docker Registry [ which makes it easy for anyone to share their container recipes (Dockerfiles) what problem does it solve? (why?) "works on my computer" screenshot of onacid i already deal with this for s, why would i want to deal with it in my development environment? lighter than VMs screenshot of waiting for windows to load in VMware? VMs don't scale well: decentralized university === lots of different environments: IIS, Apache, Nginx HTML, ColdFusion, PHP, ASP, Java mysql, mssql, oracle consistent, reproducible deployments full stack portability
7
Docker: What is it? Beginning Concepts Container Dockerfile Registry
Images Dockerfile Registry what problem does it solve? (why?) "works on my computer" screenshot of onacid i already deal with this for s, why would i want to deal with it in my development environment? lighter than VMs screenshot of waiting for windows to load in VMware? VMs don't scale well: decentralized university === lots of different environments: IIS, Apache, Nginx HTML, ColdFusion, PHP, ASP, Java mysql, mssql, oracle consistent, reproducible deployments full stack portability
8
Learn By Examples / Demos
9
Describe steps to install app Leverage Docker Hub
Demo 1 Docker + tomcat Dockerfile Start from a base image Describe steps to install app Leverage Docker Hub Registry where Dockerfiles are published hub.docker.com/_/tomcat/ Demo – 01 – Running tomcat in Docker Docker operates by using a Dockerfile This file tells docker how to build the container you want to run Think of it as a cookbook, recipe, that docker will follow if it was to build a new machine for you to run your application For any given application, this involves Starting FROM a base image, think of this as a fresh server with a brand new linux distro installed on it Then we use RUN to tell docker which commands to run to get our application installed Screenshot on the right is the official Open JDK java Dockerfile published on Docker Hub Utilizes Alpine Linux as the base image (super small distro ~30mb) We’ll use the official tomcat builds to effectively skip most of these installation steps and start with an image ready to run tomcat so we can get on with running our application
10
We can use an official repository to build tomcat
Demo 1 Docker + tomcat We can use an official repository to build tomcat We’ll supply our own context.xml but more on that later Our Dockerfile will now be really short We start FROM the official tomcat dockerfile repository with the 8-alpine tag, this tell docker to start by first downloading the container that builds a container with open jdk and tomcat 8 We can use the COPY command to replace files in the container with files we have on our host machine, in this case, maybe we want to give tomcat our own version of context.xml (this is one of the files that is required to be customized with database connection info when running cascade, but more on that in a bit) We can build this container with this dockerfile directly using the docker build command, but then we’d just have a vanilla install of tomcat We would still have to package our own web app and then use the tomcat manager to deploy it to tomcat, let’s have docker do that for us!
11
Demo 1 Docker + tomcat File structure and resulting cli for docker to get us up and running We have a simple web app here, called “publish”, it’s a very small web application, with a single index.html file Important things to note: - this file and parent directory lives on our host machine (this laptop) - we will utilize a docker volume to share this local directory with our docker container - this will allow us to have access to this web app folder after we’ve “launched” our container
12
Docker build -t my-tomcat
Demo 1 Docker + tomcat Docker build -t my-tomcat This will tell docker to create a new container and name it “my-tomcat” Then you can run this container by name Docker run … my-tomcat Will still need the –it, –p and –v arguments We will see a better way to do this in demo 3 Instead, we can use docker build to create a new container with our local dockerfile -t names the container so we can do: Docker run …. <container_name>
13
Demo 1 Docker + tomcat Demo slide of tomcat running locally with the copied publish
14
ENV – environment variables Strategy for defining configuration
Demo 2 Docker + mysql ENV – environment variables Strategy for defining configuration Demo 2 - Persisting data Containers are meant to be stateless, transient, ephemeral -v in last demo When we want to container to persist data, we utilize data volumes hub.docker.com/r/mysql/mysql-server/ Official builds often use environment variables as a shorter way of configuring your container without having to use the COPY command to replace files - remember that changes to the file structure of your container will require an extra image being added to your container being built - environment variables offer a shortcut around this This is a strategy that is often used in local development with docker, but security should strongly be considered when using this in a test or production environment To get our
15
Demo 2 Docker + mysql File structure and resulting cli for docker to get us up and running We have a simple web app here, called “publish”, it’s a very small web application, with a single index.html file Important things to note: - this file and parent directory lives on our host machine (this laptop) - we will utilize a docker volume to share this local directory with our docker container - this will allow us to have access to this web app folder after we’ve “launched” our container
16
docker build –t my-mysql docker run –it –p 3302:3306
Demo 2 Docker + mysql docker build –t my-mysql docker run –it –p 3302:3306 -v $(pwd)/mysql-data:/var/lib/mysql my-tomcat Breakdown of our tomcat.sh bash script docker run: we are telling docker to run this container -it : actually two arguments, -I is for interactive, which means this container will utilize the CLI’s standard input/output (STDIN/STDOUT/STDERR), -t will tell docker to use a pseudo-tty for this container - this will allow us to stop the container much like we would stop any other process -p: 8080:8080: Here we are mapping the container’s port 8080 with our host’s (laptop) port 8080, resulting into tomcat being accessible from our browser at Tomcat:8-alpine **this will only run the Dockerfile in the docker hub registry, nothing special here**
17
Demo 2 Docker + mysql Breakdown of our tomcat.sh bash script
docker run: we are telling docker to run this container -it : actually two arguments, -I is for interactive, which means this container will utilize the CLI’s standard input/output (STDIN/STDOUT/STDERR), -t will tell docker to use a pseudo-tty for this container - this will allow us to stop the container much like we would stop any other process -p: 8080:8080: Here we are mapping the container’s port 8080 with our host’s (laptop) port 8080, resulting into tomcat being accessible from our browser at -v: this is our volume mapping command we are telling docker to create a volume container with our current directory/webapps and mount it to the /usr/local/tomcat/webapps directory inside the container instead of seeing the regular default tomcat webapps folder that tomcat comes with in an vanilla install, tomcat will instead see our webapps folder with the publish webapp tomcat:8-alpine: here we are telling it which repository/container to build
18
Tying it all together Items you will need
Demo 3 Docker + cascade Tying it all together Items you will need Local development license from Hannon Hill Cascade SQL seed script Setting-up-the-database-MySQL- Cascade Downloaded Breakdown of our tomcat.sh bash script docker run: we are telling docker to run this container -it : actually two arguments, -I is for interactive, which means this container will utilize the CLI’s standard input/output (STDIN/STDOUT/STDERR), -t will tell docker to use a pseudo-tty for this container - this will allow us to stop the container much like we would stop any other process -p: 8080:8080: Here we are mapping the container’s port 8080 with our host’s (laptop) port 8080, resulting into tomcat being accessible from our browser at -v: this is our volume mapping command we are telling docker to create a volume container with our current directory/webapps and mount it to the /usr/local/tomcat/webapps directory inside the container instead of seeing the regular default tomcat webapps folder that tomcat comes with in an vanilla install, tomcat will instead see our webapps folder with the publish webapp tomcat:8-alpine: here we are telling it which repository/container to build
19
cascade.sql in mysql directory
Demo 3 Docker + cascade context.xml Modified per cascade instructions help.hannonhill.com/hc/en-us/articles/ Installation-using-the-ZIP-file- cascade.sql in mysql directory COPY ./cascade.sql /docker-entrypoint- initdb.d/db.sql ROOT added to tomcat/webapps directory This is ROOT.zip downloaded from hannonhill.com docker-compose.yml - ??? We are pretty much using the previous examples without change The context.xml I hinted at in our first demo is just the cascade configured context.xml file ROOT in tomcat/webapps is the cascade we downloaded from hannonhill.com, we don’t need to make any modifications to this directory And last but not least, docker-compose.yml
20
Updated tomcat Dockerfile New COPY addition
Demo 3 Docker + cascade Updated tomcat Dockerfile New COPY addition Our Dockerfile will now be really short We start FROM the official tomcat dockerfile repository with the 8-alpine tag, this tell docker to start by first downloading the container that builds a container with open jdk and tomcat 8 We can use the COPY command to replace files in the container with files we have on our host machine, in this case, maybe we want to give tomcat our own version of context.xml (this is one of the files that is required to be customized with database connection info when running cascade, but more on that in a bit) We can build this container with this dockerfile directly using the docker build command, but then we’d just have a vanilla install of tomcat We would still have to package our own web app and then use the tomcat manager to deploy it to tomcat, let’s have docker do that for us!
21
Demo 3 Docker + cascade What is docker compose? Containers should follow the single responsibility rule Compose is a tool for defining and running multi-container Docker applications Allows us to also describe our runtime arguments (-v, -p, etc) The last thing we want to do is make one big Dockerfile describing our mysql and tomcat application. Since containers are cheap, we can separate our concerns and define each application block in it’s own container Compose is a tool for defining and running multi-container Docker applications We can then use docker compose commands to bring up or down our entire application stack (or even parts of the stack) Things to note here: The service names have meaning, we can instruct docker compose to bring up a single service using these names docker-compose up tomcat Or just to build when we make changes: docker-compose build tomcat These names are just used by docker-compose, docker will generate a container specific name Links: this sets up service discovery, this is the real magic Using link: mysql:mysql in the tomcat service tells docker to make sure the tomcat container can talk with our mysql container using the name “mysql” This allows us to setup our database connection to cascade inside our context.xml using the host address: mysql
22
docker-compose build docker-compose up Demo 3 Docker + cascade
Breakdown of our tomcat.sh bash script docker run: we are telling docker to run this container -it : actually two arguments, -I is for interactive, which means this container will utilize the CLI’s standard input/output (STDIN/STDOUT/STDERR), -t will tell docker to use a pseudo-tty for this container - this will allow us to stop the container much like we would stop any other process -p: 8080:8080: Here we are mapping the container’s port 8080 with our host’s (laptop) port 8080, resulting into tomcat being accessible from our browser at Tomcat:8-alpine **this will only run the Dockerfile in the docker hub registry, nothing special here**
23
To run out last demo we need only to run: docker-compose up
Demo 3 Docker + cascade To run out last demo we need only to run: docker-compose up
24
Wrap-Up / More Resources
25
Where do we go from here? Dockerize one or your environments!
Docker Hub is your friend Official Docker Newsletter Docker Captains Network Dockercon on YouTube Today’s demos Best next steps is to try it yourself! - My initial steps was utilizing docker to replicate our wordpress setup, but I first just started with nginx and php for locallly testing some php files - Searching for a reading other people’s dockerfiles is the best way to use docker hub Docker puts out a weekly newsletter, not just highlighting their latest developments, but often featuring HOWTO tutorials and blog posts from the community Also gives a good calendar on upcoming meetups Docker’s evangelists are called Docker Captains. They are usually very prolific on the web, sharing their own projects via blog posts and videos For the past couple of years, DockerCon, the yearly convention held by Docker livestream on youtube and are also a great place to learn
26
Questions? and Thanks!
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.