# IoT Lab 5 Docker Container
## Set up a Docker environment.
### Print all local docker images

### Run a ‘hello-world’ container in the docker

### Print all running docker process status

### Print all docker process status

## Run a Webapp with Docker.
Run the `docker run` command to publish ports in detached mode

See the ports

Open http://localhost:32769 in browser

## Make your first Docker image
### Trouble
[I just saw the hints in lab handout after resolving the error:(]
Encountered the `werkzeug not found` error, which is caused by Flask not specifying the dependency correctly and installed Werkzeug 3.0.0 which Flask 2.0.2 not support.

### Troubleshooting
Specify `Werkzeug==2.2.2` in the `requirements.txt`

Delete the old image.

Rebuild it.

Image successfully running.

Cat gif display on server.


## Multi-container environment
### Run FoodTrucks
Able to send a request to the Elasticsearch container

Show that we talk to ES on `172.17.0.2:9200`




### How a microservice architecture is implemented
#### How the Docker Network work
Docker Network allows custom networks, and multiple containers can be attached to the custom netwotk by utilizing the `--net` flag in the `docker run` command. It also allows containers to communicate with each other and establish connections to the Internet.
In FoodTrucks app, two containers - one running the Flask process and another running the Elasticsearch (ES) process are running in the same user-defined network so that they are able to communicate each other.
#### How the Docker Compose work
Compose is a tool for defining and running multi-container Docker applications. With `docker-compose.yaml` that configures application's services, it enables the easy launch of an application with several containers through command `docker-compose up`.
`docker-compose.yaml` of FoodTrucks app
```
version: "3"
services:
es:
image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
container_name: es
environment:
- discovery.type=single-node
ports:
- 9200:9200
volumes:
- esdata1:/usr/share/elasticsearch/data
web:
image: wzr1123/foodtrucks-web
command: python3 app.py
depends_on:
- es
ports:
- 5000:5000
volumes:
- ./flask-app:/opt/flask-app
volumes:
esdata1:
driver: local
```
Then by running `docker-compose up` under `FoodTrucks` directory, the app will be hosted on `http://0.0.0.0:5000/`.