Skip to content
Snippets Groups Projects
Commit 08f10957 authored by Sastry, Nishanth Prof (Comp Sci & Elec Eng)'s avatar Sastry, Nishanth Prof (Comp Sci & Elec Eng)
Browse files

Update README.md

parent 4dc1aeab
No related branches found
No related tags found
No related merge requests found
# Instructions
## Step 1: microservices introductory demo
......@@ -145,12 +144,32 @@ Essentially `docker-compose.yaml` the same information as in the Makefile, but e
The service can be started with `docker-compose up` (or with `docker-compose up --build` to build the image itself). If you make a change to the service, you can run `docker-compose down` and `docker-compose up --build` to bring down, rebuild and bring up the service again. If you are merely intending to restart the service, you can run `docker-compose stop` and `docker-compose start`.
## Even further steps -- changing the running code in a container using volumes
The [docker compose specification](https://github.com/compose-spec/compose-spec/blob/master/spec.md) gives full details about what you can say in a `docker-compose.yaml` file. There is also a [Getting Started](https://docs.docker.com/compose/gettingstarted/) guide and a [full reference of the Docker Compose CLI](https://docs.docker.com/compose/reference/).
## Even further steps
> The above is already much more easier than running by hand all the commands in the makefile, or creating the makefile from scratch. However, during development, we will frequently find that the source code within the container has a bug and we need to make a tiny change and restart the service. This quickly becomes a pain. We can avoid this if we can figure out a way to change source code within a running container.
Volumes are a way to map a directory in the host with a directory in the running container. This can be used for various things -- e.g., you can use it to output files or other persistent information from a running container to the host. You can also use it to have the running container read files from the host, passing config details and secrets (e.g., passwords).
You can find out more about config and secrets in the [docker compose specification](https://github.com/compose-spec/compose-spec/blob/master/spec.md). Essentially, they are a way to create volumes with appropriate file permissions for read, write ane execute privileges. Here, we learn how to ``hot reload'' a source file in a running Docker container.
Hot reload requires two things - (i) a change made to a source file in the host container should be visible in the running Docker container. (ii) the changed source code should be picked up by the running service. To enable (ii) we use a capability of Flask. By setting the environment variable FLASK_ENV=development, the running Flask service picks up any change to the underlying source code and reflects it immediately when we next issue an HTTP request. To set this environment variable, we use the `env` element in Docker-compose.yaml. To enable the Flask /within the container/ to recognise a change in the source code made in the host, we map the source code directory in the host to a directory within the container. Note that it is not allowed to map a host directory to the root (/) directory of the container. Therefore, we have to move the source code to another directory (say /src/) in the container. We change movieservice's Dockerfile to reflect this (see the diff between the corresponding movieservice Dockerfiles in this branch and other branches).
The docker-compose.yaml for this directory contains the required changes for `movieservice`. To see this that enables a change to be directly reflected, bring up the services with `docker-compose up` (this should be run from the root directory where the docker-compose.yaml file is) and run the `curl` test as before:
```console
$ curl 127.0.0.1:5002/showtimes/20151130
["The Good Dinosaur", "The Martian", "Spectre"]%
```
Now, if you uncomment line 31 of movieservice.py and run `curl` again, you should see that the movie titles changes from `The Good Dinosaur` `The Martian' and `Spectre` to `Hello world` in each case:
```console
$ curl 127.0.0.1:5002/showtimes/20151130
["hello world", "hello world", "hello world"]%
```
Note that if you change anything in showtimes.py, this is not reflected immediately as the stservice container does not have a volume mapping. **As an exercise, implement hot source swapping for the stservice container as well.**
# credits
The original code is taken from https://github.com/umermansoor/microservices
It has been lightly modified for Python3 compatibility, and further simplified to showcase microservice communications.
We have also added a demo of dockerization
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment