Skip to content

Commit

Permalink
feat: add compose task
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsvetan Ivanov authored and Varban Andreev committed May 11, 2020
1 parent fb4deaf commit cacf818
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 16 deletions.
16 changes: 7 additions & 9 deletions Tasks/4.Building images/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# Practice - building images

Your project utilizes microservices and Kuberenetes. On your cluster you have many containers (pods) with your services. There's a special container which runs Ubuntu and can access the other services' databases and other components. To access those components you install a few CLI tools on this special container. The problem - each time the cluster is re-deployed you must install the CLI tools again because they're not part of the container's base Ubuntu image.
Your project utilizes microservices and Kuberenetes. On your cluster you have many containers (pods) with your services. Theres a special container **jumpbox** which runs Ubuntu and can access the other services' databases and other components. To access those components you install a few CLI tools on this special container. The problem - each time the cluster is re-deployed you must install the CLI tools again because they're not part of the container's base Ubuntu image.

You want to automate this process by building a Dockerfile for this container using ubuntu:18.04 as your base image.
You want to automate this process by building a Dockerfile for this container using **ubuntu:18.04** as your base image.

To install those tools you normally use the following commands:

- $ `DEBIAN_FRONTEND=noninteractive` # Env var required for postgres
- $ `DEBIAN_FRONTEND=noninteractive` # Env var required for postgres installation
- $ `apt-get update && apt-get install -y postgresql` # Install postgres to access dbs
- $ `apt-get install -y wget` # Install wget for downloading software packages
- $ `apt-get install -y curl` # Install curl for running HTTP requests

:whale: HINT: Research how to set environment variables inside Dockerfiles for the DEBIAN_FRONTEND variable.

To build the image, navigate to your Dockerfile path and use
- `docker build –t "<name>:<tag>" .`

Run a container from this image in interactive mode and verify the installations:
1. Create the above Dockerfile and build an image **jumpbox** with a **1.0** tag. Run a container with interactive bash and verify the installations:
- `psql --version` # You should see the psql version
- `wget --version` # You should see the wget version and other info
- `curl 'http://example.com'` # You should see some html
2. Change **curl** to **inetutils-ping**. Build a jumpbox version **2.0** and test again:
- `psql --version`
- `ping 8.8.8.8`
14 changes: 7 additions & 7 deletions Tasks/5.Using volumes/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Practice - using volumes

Run a container "mypsql" using **postgres:12** with options to:
- run the container in detached mode
- pass an environment variable `POSTGRES_PASSWORD=secretpass`
- create a named volume with `-v <name>:/var/lib/postgresql/data`
Run a container **mypsql** using **postgres:12** with options to:
- run in detached mode
- pass the appropriate environment variable (find it on https://hub.docker.com/)
- use a named volume

Run a shell in the container and use psql to add a table and a record:
Run bash in the container and use psql to add a table and a record:
- $ `psql -U postgres`
- $ `create table public.films (id int PRIMARY KEY, name varchar(255));`
- $ `insert into films(id, name) values(1, 'Some movie');`

Exit the container and delete it. Run a new container with the same options. Use ***the same*** volume name to re-use the existing volume.
Exit the container and delete it. Run a new container with the same options (use ***the same*** volume name).

Run a shell inside the container and see if your data is still there:
Run bash inside the new container and see if your data has survived:
- $ `psql –U postgres`
- $ `select * from public.films;`
7 changes: 7 additions & 0 deletions Tasks/6.Compose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Practice - Docker Compose

## Fix _docker-compose.yml_ and ensure the Voting app is working properly
- Review the Voting app [diagram](./voting-app.png)
- Fix [docker-compose.yml](./docker-compose.yml)
- Execute command: docker-compose up
- Ensure the Voting app is working properly
47 changes: 47 additions & 0 deletions Tasks/6.Compose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: "2"

services:
vote:
image: dockersamples/examplevotingapp_vote:latest
networks:
- front-end-subnet
ports:
- "80:80"

# Hint: On which port the container is listening?
result:
image: dockersamples/examplevotingapp_result:latest
networks:
- back-end-subnet
ports:
- "8080:8080"

# Hint: What network is going to be attached to the worker service?
worker:
image: dockersamples/examplevotingapp_worker:latest
depends_on:
- "redis"
- "db"

# Hint: Should we care about the service name?
redis-mredis:
image: redis:3.2
networks:
- front-end-subnet

# Hint: environment variable should be set to allow connections without setting database password
db:
image: postgres:9.4
networks:
- back-end-subnet
volumes:
- db-data:/var/lib/postgresql/data

# Hint: Do we need volumes section?

# Hint: Do we need special network drivers to run the app?
networks:
front-end-subnet:
driver: custom
back-end-subnet:
driver: bridge
Binary file added Tasks/6.Compose/voting-app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cacf818

Please sign in to comment.