diff --git a/build6/apache/Dockerfile b/build6/apache/Dockerfile new file mode 100644 index 0000000..207232a --- /dev/null +++ b/build6/apache/Dockerfile @@ -0,0 +1,10 @@ +FROM tomcat:9-jdk11-openjdk + +RUN mkdir /usr/local/tomcat/webapps/ROOT/ + +COPY /app /usr/local/tomcat/webapps/ROOT/ + +CMD ["catalina.sh", "run"] +# The commands to run this simple tomcat server are as follows. +# docker build -t tomcat-test . +# docker run tomcat-test -p 8080:8080 \ No newline at end of file diff --git a/build6/apache/app/index.html b/build6/apache/app/index.html new file mode 100644 index 0000000..bc8441d --- /dev/null +++ b/build6/apache/app/index.html @@ -0,0 +1,23 @@ + + +
+ + + + +Well not really.
+ + + \ No newline at end of file diff --git a/build6/docker-compose.yml b/build6/docker-compose.yml new file mode 100644 index 0000000..8ee6f27 --- /dev/null +++ b/build6/docker-compose.yml @@ -0,0 +1,24 @@ +version: '1' +services: + mariadb: + environment: + - MYSQL_USER=Username + - MYSQL_PASSWORD=Password + - MYSQL_ROOT_PASSWORD=rootPassword + - MYSQL_ROOT_HOST=% + - TZ=America/New_York + build: + context: ./mariadb + volumes: + - maria-data:/var/lib/mysql + ports: + - 3306:3306 + + apache: + build: + context: ./apache + ports: + - 8080:8080 + +volumes: + maria-data: diff --git a/build6/mariadb/Dockerfile b/build6/mariadb/Dockerfile new file mode 100644 index 0000000..2634ce5 --- /dev/null +++ b/build6/mariadb/Dockerfile @@ -0,0 +1,3 @@ +FROM mariadb:10.4 + +COPY ./mysql-init.sql /docker-entrypoint-initdb.d \ No newline at end of file diff --git a/build6/mariadb/mysql-init.sql b/build6/mariadb/mysql-init.sql new file mode 100644 index 0000000..b70b8a4 --- /dev/null +++ b/build6/mariadb/mysql-init.sql @@ -0,0 +1,14 @@ +create database test; +use test; + +CREATE TABLE table_name +( +id INTEGER AUTO_INCREMENT, +first_name varchar(255), +last_name varchar(255), +primary key (id) +); + +/*INSERT INTO table_name (first_name, last_name) +VALUES ("John", "Doe"); +*/ \ No newline at end of file diff --git a/module2.md b/module2.md index b4af71f..1952d25 100644 --- a/module2.md +++ b/module2.md @@ -120,4 +120,57 @@ In this exercise we will setup two containers that will talk over a bridged netw 8. Now type the command ```curl -s http://webserver01/wineglas.vt | pv -L3000 -q``` 9. Cheers! + +### Exercise 7 Working with Docker Compose + +A docker compose file is used to run a multi-container docker application such as a front end server and a back end server. Docker compose can automatically create both containers and network them together. A compose file also holds configuration variables that can be changed depending on the environment or version of the application that is run in the containers. There are more advanced features and uses for docker compose found on the docker docs website https://docs.docker.com/compose/ + +For now, we are going to cover the basics of docker compose and set up a basic multi-container application. + +1. Go to the build6 directory and take a look at the docker compose file and the docker files inside of mariadb folder and apache folder. For a docker compose to work this is the minimum information needed in the docker file. + +2. Now navigate to the directory where the docker-compose file is and run the ```command docker compose up -d``` This should run both the apache server for a static webpage and a mariadb database. + +3. Go to localhost:8080 to see a webpage running in docker! + +4. Now find the index.html file in apache/app/index.html and change something about the webpage. + +5. Run ```docker compose down``` to stop and delete the containers and delete the image ```build6_apache``` (if you need a hint look at exercise 2). + +6. Run ```docker compose up -d``` docker will recompile the apache image and use the old mariadb image. Refresh the page and check out your changes! + +7. Don't forget to clean up the containers and images when you are done! + +### Exercise 8 Cron Job and Docker + +Cron is a job scheduler on unix like operating systems. These jobs run on a desired schedule depending on the configurations in the file. For more information on cron visit [THIS](https://en.wikipedia.org/wiki/Cron) website for an overview. In this exercise we will cover a simple cron job to spin up a container and have it run a command then exit. This is ideal for running weekly reports or ingests. + + +1. Run “crontab -e” If it is your first time adding a cron job then it will prompt you with an empty file to edit in vim. +2. For help creating the command a common comment is used to help remember the formatting. +``` +# ┌───────────── minute (0 - 59) +# │ ┌───────────── hour (0 - 23) +# │ │ ┌───────────── day of the month (1 - 31) +# │ │ │ ┌───────────── month (1 - 12) +# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday; +# │ │ │ │ │ 7 is also Sunday on some systems) +# │ │ │ │ │ +# │ │ │ │ │ +# * * * * *