Step-by-step installation on Docker
===================================

Install Docker
--------------

This installation process of Docker is well documented online. The installation can be done very easely with one of the following command:

.. code-block:: bash

    $ curl -fsSL get.docker.com -o get-docker.sh
    $ sh get-docker.sh

To run the docker commands without beeing root, you need to execute the following command:

.. code-block:: bash

	$ sudo usermod -aG docker $(whoami)

In a second step, you have to install docker-compose with the following commands:

.. code-block:: bash
	
	$ sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
	$ sudo chmod +x /usr/local/bin/docker-compose

The latest version of docker-compose should be downloaded (1.21.2 at this moment as mentionned in the download URL). See the |dockerinstalldoc| and |dockercomposedoc| for more details.

Download the PiAnoS image
-------------------------

The PiAnoS image can be downloaded and run directly by cloning the docker image and running it, with the following commands:

.. code-block:: bash

	$ git clone --recursive https://esc-md-git.unil.ch/PiAnoS/docker.git .
	$ docker-compose up --build -d

This commandes will clone the docker image in the current directory. Make an appropriate folder before cloning the git repository.

By default, this command will compose-up a web front-end binded on port 80, and a PostgreSQL database, not accessible from the outside world. If you want to change the port configuration, edit the `docker-compose.yml` file.

Configuration
-------------

The next step is the configuration of PiAnoS via the web interface. In this case, the Database Hostname has to be container name of the posgresql database, i.e. ``db``. The name of the container can be changed in the ``docker-compose.yml`` file.

The configuration of the PiAnoS instance can be done in the configuration file present in the ``./apache/src/backend/settings-local.php``.

Run the image
-------------

To run PiAnoS in detached mode, use this command:

.. code-block:: bash

    $ docker-compose up -d

To see and follow the logs, use this command:

.. code-block:: bash

    $ docker-compose logs -f

If you have any binding problems, check if you have any docker image alreay up and running with the :

.. code-block:: bash

	$ docker ps

command. If so, you can remove all running images with the following command:

.. code-block:: bash

	$ docker rm -f $(docker ps -aq)

The docker cache can be cleard by typing:

.. code-block:: bash

    $ docker rm -f $(docker ps -aq)
    $ docker rmi -f $(docker images -aq)
    $ docker system prune

..
	Links

.. |dockerinstalldoc| raw:: html

	<a href="https://docs.docker.com/engine/installation/" target="_blank">Docker installation documentation</a>

.. |dockercomposedoc| raw:: html

	<a href="https://docs.docker.com/compose/install/#install-compose" target="_blank">Docker-compose installation documentation</a>
