Skip to content

Commit

Permalink
For Docker standalone tutorial, do not use --net=host (#465)
Browse files Browse the repository at this point in the history
* For Docker standalone tutorial, do not use --net=host but instead put the containers in a dedicated docker network. More stable behaviour across OSes.

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* add changelog entry and link the docker-compose tutorial in the toy tutorial

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
  • Loading branch information
nhoening committed Jul 21, 2022
1 parent 0a4f300 commit 9d62a1c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -19,6 +19,7 @@ Bugfixes
-----------
* Do not fail asset page if entity addresses cannot be built [see `PR #457 <http://www.github.com/FlexMeasures/flexmeasures/pull/457>`_]
* Time scale axes in sensor data charts now match the requested date range, rather than stopping at the edge of the available data [see `PR #449 <http://www.github.com/FlexMeasures/flexmeasures/pull/449>`_]
* The docker-based tutorial now works with UI on all platforms (port 5000 did not expose on MacOS) [see `PR #465 <http://www.github.com/FlexMeasures/flexmeasures/pull/465>`_]

Infrastructure / Support
----------------------
Expand Down
9 changes: 6 additions & 3 deletions documentation/dev/docker-compose.rst
Expand Up @@ -73,21 +73,24 @@ The postgres database is a test database with toy data filled in when the flexme
You could also connect it to some other database (on your PC, in the cloud), by setting a different ``SQLALCHEMY_DATABASE_URI`` in the config.


.. _docker-compose-tutorial:

Seeing it work: Running the toy tutorial
--------------------------------------

A good way to see if these containers work well together, and maybe to inspire how to use them for your own purposes, is the :ref:`tut_toy_schedule`.
The server container already creates the toy account when it starts. We'll now run the rest of that tutorial, with one twist at the end, when we create the battery schedule.

Let's go into the worker container:
The `flexmeasures-server` container already creates the toy account when it starts (see its initial command). We'll now walk through the rest of the toy tutorial, with one twist at the end, when we create the battery schedule.

Let's go into the `flexmeasures-worker` container:

.. code-block:: console
docker exec -it flexmeasures-worker-1 bash
There, we add the price data, as described in :ref:`tut_toy_schedule_price_data`. Create the prices and add them to the FlexMeasures DB in the container's bash session.

Next, we put a scheduling job in the worker's queue. This uses the Redis container ― the toy tutorial isn't doing that (the difference is ``--as-job``).
Next, we put a scheduling job in the worker's queue. This only works because we have the Redis container running ― the toy tutorial doesn't have it. The difference is that we're adding ``--as-job``:

.. code-block:: console
Expand Down
6 changes: 4 additions & 2 deletions documentation/tut/toy-example-from-scratch.rst
Expand Up @@ -46,8 +46,9 @@ Install Flexmeasures and the database
$ docker pull lfenergy/flexmeasures:latest
$ docker pull postgres
$ docker run --rm --name flexmeasures-tutorial-db -e POSTGRES_PASSWORD=fm-db-passwd -e POSTGRES_DB=flexmeasures-db -d -p 5433:5432 postgres:latest
$ docker run --rm --name flexmeasures-tutorial-fm --env SQLALCHEMY_DATABASE_URI=postgresql://postgres:fm-db-passwd@localhost:5433/flexmeasures-db --env SECRET_KEY=notsecret --env FLASK_ENV=development --env LOGGING_LEVEL=INFO -d --net=host lfenergy/flexmeasures
$ docker network create flexmeasures_network
$ docker run --rm --name flexmeasures-tutorial-db -e POSTGRES_PASSWORD=fm-db-passwd -e POSTGRES_DB=flexmeasures-db -d --network=flexmeasures_network postgres:latest
$ docker run --rm --name flexmeasures-tutorial-fm --env SQLALCHEMY_DATABASE_URI=postgresql://postgres:fm-db-passwd@flexmeasures-tutorial-db:5432/flexmeasures-db --env SECRET_KEY=notsecret --env FLASK_ENV=development --env LOGGING_LEVEL=INFO -d --network=flexmeasures_network -p 5000:5000 lfenergy/flexmeasures
$ docker exec flexmeasures-tutorial-fm bash -c "flexmeasures db upgrade"
Now - what's *very important* to remember is this: The rest of this tutorial will happen *inside* the ``flexmeasures-tutorial-fm`` container! This is how you hop inside the container and run a terminal there:
Expand All @@ -67,6 +68,7 @@ Install Flexmeasures and the database
.. note:: A tip on Linux/macOS ― You might have the ``docker`` command, but need `sudo` rights to execute it. ``alias docker='sudo docker'`` enables you to still run this tutorial.

.. note:: Got docker-compose? You could run this tutorial with 5 containers :) ― Go to :ref:`docker-compose-tutorial`.

.. tab:: On your PC

Expand Down

0 comments on commit 9d62a1c

Please sign in to comment.