Running TPA in a Docker container
=================================

If you’re using a system for which there are no :ref:`Installing TPA packages <Installing TPA packages>`  available,
and it’s difficult to run TPA after :ref:`Building and installing from source <Building and installing from source>`  (for example, because
it’s not easy to obtain a working Python 3.9+ interpreter), your last
resort might be to build a Docker image and run TPA inside a Docker
container.

You don’t need to run TPA in a Docker container to :ref:`deploy to Docker containers <Docker>`  . It’s
always preferable to run TPA directly if you can, even on MacOS X.

Quick start
-----------

Make sure you have Docker installed and working on your system.

To clone the tpaexec source repository from Github and build a new
Docker image named ``tpa/tpaexec`` , run the following commands:

.. code:: bash

   $ git clone ssh://git@github.com/EnterpriseDB/tpa.git
   $ cd tpa
   $ docker build -t tpa/tpaexec .

Double-check the created image:

.. code:: bash

   $ docker image ls tpa/tpaexec
   REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
   tpa/tpaexec   latest    e145cf8276fb   8 seconds ago   1.73GB
   $ docker run --platform=linux/amd64 --rm tpa/tpaexec tpaexec info
   #  TPAexec v20.11-59-g85a62fe3 (branch: master)

   tpaexec=/usr/local/bin/tpaexec
   TPA_DIR=/opt/EDB/TPA
   PYTHON=/opt/EDB/TPA/tpa-venv/bin/python3 (v3.7.3, venv)
   TPA_VENV=/opt/EDB/TPA/tpa-venv
   ANSIBLE=/opt/EDB/TPA/tpa-venv/bin/ansible (v2.8.15)

Create a TPA container and make your cluster configuration directories
available inside the container:

.. code:: bash

   $ docker run --platform=linux/amd64 --rm -v ~/clusters:/clusters \
       -it tpa/tpaexec:latest

You can now run commands like ``tpaexec provision /clusters/speedy`` at
the container prompt. (When you exit the shell, the container is
removed.)

If you want to provision Docker containers using TPA, you must also
allow the container to access the Docker control socket on the host:

::

   $ docker run --platform=linux/amd64 --rm -v ~/clusters:/clusters \
       -v /var/run/docker.sock:/var/run/docker.sock \
       -it tpa/tpaexec:latest

Run ``docker ps`` in the container to make sure that your connection to
the host Docker daemon is working.

Installing Docker
-----------------

See the `Docker documentation <https://docs.docker.com>`_  if you need help `installing Docker <https://docs.docker.com/install>`_  and `getting started <https://docs.docker.com/get-started/>`_ 
with it.

On MacOS X, you can and launch Docker from the application menu.
