Introduction
There are a few different ways of getting Tryton running on your system. One of these is by using Docker. The aim here is to help you get a basic Tryton system up and running using Docker, even if you have never used it before, and to teach you a bit about it along the way.
If you are familiar with Docker and know what you are doing, then the instructions on the tryton/tryton docker image are much shorter and will let you try out Tryton in seconds. These instructions are much longer, provide a slightly different setup, and try to explain each step in detail.
As Tryton has a three tier architecture there are several different components that you need in order to get a functioning Tryton system. This turns out to be a good fit for Docker as Docker is designed to run applications that are made up of multiple different components.
Install Docker
None of this is possible without having Docker installed on your system. So the very first thing you are going to need to do is install Docker. How you do this will depend on what operating system you are using. Fortunately the official Docker Documentation can help you here.
For linux you may also want to run the Linux post-installation steps so you don’t need to preface the docker
commands with sudo
.
Once you have got docker installed and running you will be ready for the next stage.
Docker Concepts
If you have never used Docker before, then some of the terminology and ideas behind it may seem a bit strange. However, if you can grasp a few of the key concepts it should help you understand what is going on.
-
Container
Fundamentally a Docker container is just a running program. Once it has been created, you can use Docker to start, pause, unpause and stop it. Each container is isolated from the host it is running on, and all the other containers on the system. It also has its own private filesystem, which is initially provided by a Docker image. Containers are often treated as disposable. Extra setup is required to keep any data a container generates because when a container is removed all its data is lost. You can run as many containers as you like that are based on the same Docker image. -
Image
A Docker image provides the filesystem that is used when starting a Docker container. It contains all the binaries, code, runtimes, dependencies and data needed by a program. Each image is made up from multiple readonly layers. The files in each layer add to or replace those in the layers below them. When a container is started using the image the container adds a final read/write layer on top of the image. Any changes done by the container only happen in this read/write layer.
Create a Docker Bridge Network
As the Docker containers are isolated from each other, you need to setup a way for them to communicate so they can do useful things. Just like normal computers, the standard way this is done in Docker is over a network. Docker provides commands that create and manage what are called user-defined bridge networks. Any containers that are attached to the same user-defined bridge network will be able to talk to each other.
Create a user-defined bridge network called tryton
, for use with your Tryton containers, by running:
docker network create tryton
Run the Database Server
Conceptually in the three tier architecture this is the bottom most tier, and is where the majority of the data in your Tryton system is stored. For production systems Tryton currently supports the use of PostgreSQL as the database server.
As a side note, something that sometimes confuses people is the use of the term database to both mean:
- the related collection of structured data that is stored together, and
- the program that manipulates and manages access to this data.
In this document I will try to refer to the former as the database, and the later as the database server. So, a database server may contain multiple different databases.
Create a Docker Volume for the Database
As described previously, Docker containers are often treated as disposable. To ensure your data doesn’t vanish if you if you replace your PostgreSQL container you can use a Docker volume.
docker volume create tryton-database
This command creates a Docker volume called tryton-database
which can then be mounted inside a container. Any data stored in the volume by the container will still exist even after the container it was mounted in has gone.
Generate a Secure Password
To secure your data ideally you should generate a strong password for use with your database. You will also need to remember this password, because you will need it to restart your Tryton system if it gets removed. Using a password manager can help you do this.
You will then need to replace the ${POSTGRES_PASSWORD} in the commands below with the password you generated. Alternatively you can set the password in your environment, and the commands will pick it up from there:
export POSTGRES_PASSWORD='your_top_secret_password'
Start the PostgreSQL Container
In order to be able to run PostgreSQL in a container you need a PostgreSQL Docker image. This is provided by the officially supported postgres image on Docker Hub.
By default, if you try and use a Docker image, and you don’t have it on your system, then Docker will automatically attempt to download it (or pull it in Docker terminology) from Docker Hub for you.
So, you should now be ready to start the database server using this command (remembering to replace ${POSTGRES_PASSWORD}, if required):
docker run \
--name tryton-postgres \
--env PGDATA=/var/lib/postgresql/data/pgdata \
--env POSTGRES_DB=tryton \
--env POSTGRES_PASSWORD="${POSTGRES_PASSWORD}" \
--mount source=tryton-database,target=/var/lib/postgresql/data \
--network tryton \
--detach \
postgres
What this command does is:
- starts a new Docker container (line 1) based on the latest postgres Docker image (line 9)
- names the container
tryton-postgres
(line 2), and - attaches the container to the
tryton
network (line 7) - tells PostgreSQL to create a database called
tryton
(line 4) - it sets the username and password needed to connect to
postgres
(default) andyour_top_secret_password
(line 5) - inside the container it mounts the
tryton-database
volume at/var/lib/postgresql/data
(line 6), and - tells PostgreSQL to store the database in
/var/lib/postgresql/data/pgdata
(line 3), so its data is stored in the Docker volume, and finally - detaches your terminal’s standard input, output and error from the container so you get the command prompt back (line 8).
Note: If you want to run a specific version of PostgreSQL, so you can control when you upgrade, then you need to specify which one using a tag along with the image name, e.g.: for version 12 use postgres:12
instead of postgres
.
Initialize the Database
Now that you have your database server running you can initialize the database so it is ready for use. This command can take a few seconds to run, and near the end you will be prompted to enter the email address and password you want to use for the admin
user (once again don’t forget to replace ${POSTGRES_PASSWORD}, if required).
docker run \
--env DB_HOSTNAME=tryton-postgres \
--env DB_PASSWORD="${POSTGRES_PASSWORD}" \
--network tryton \
--interactive \
--tty \
--rm \
tryton/tryton \
trytond-admin -d tryton --all
What this command does is:
- starts a new docker container (line 1) based on the latest tryton Docker image (line 8), and
- attaches the container to the
tryton
network (line 4), and - in the container runs the
trytond-admin
command against thetryton
database and initializes and updates everything using the--all
option (line 9) - it ensures the correct database server is used (line 2) with the correct login username (default -
postgres
) and password (line 3) - allocates a pseudo-TTY (line 6) and keeps the terminal’s standard input connected to the container (line 5), so you can enter in the
admin
user’s email address and password, and - once done removes the container (line 7) because it isn’t needed anymore
Note: If you want to run Tryton from a specific series, so you can control when you upgrade, then you need to specify the series along with the image name. So for series 5.6 use tryton/tryton:5.6
instead of tryton/tryton
.
Run the Tryton Server
The Tryton server forms the middle tier in the three tier architecture and provides the business logic. Tryton’s advanced modularity allows you to select the correct business logic for your requirements by activating only the modules that you intend to use.
Create a Docker Volume for the Data
Although most of the data in your Tryton system is stored in the database, there may be some stored on the filesystem. Tryton normally stores attachments outside the database, and can be configured to store other things like copies of Sales Invoices there too. To make sure this data doesn’t disappear if you if you replace your Tryton container you can use a Docker volume.
docker volume create tryton-data
This volume needs to mounted inside any Tryton containers that get created.
Start the Tryton Server Container
Everything should now be ready for you to start your Tryton server. This can be done with this command (ensure you replace ${POSTGRES_PASSWORD}, if required):
docker run \
--name tryton \
--env DB_HOSTNAME=tryton-postgres \
--env DB_PASSWORD="${POSTGRES_PASSWORD}" \
--mount source=tryton-data,target=/var/lib/trytond/db \
--network tryton \
--publish 127.0.0.1:8000:8000 \
--detach \
tryton/tryton
What this command does is:
- starts a new docker container (line 1) based on the latest tryton Docker image (line 9), and
- names the container
tryton
(line 2), and - attaches the container to the
tryton
network (line 6) - it ensures the correct database server is used (line 3) with the correct login username (default -
postgres
) and password (line 4) - inside the container it mounts the
tryton-data
volume at/var/lib/tryton/db
(line 5) so any documents Tryton saves to the filesystem won’t get lost, and - allows you to connect to your Tryton server by forwarding connections to
127.0.0.1:8000
to the container’s port8000
(line 7) - detaches your terminal’s standard input, output and error from the container so you get the command prompt back (line 8).
Note: you should make sure that the series of Tryton that you are using is the same as the one you used when you initialized the database. So for series 5.6 use tryton/tryton:5.6
instead of tryton/tryton
.
Note: using this command you will only be able to connect to your Tryton server from the computer it is running on. If you want to be able to connect to it over the network you need to change 127.0.0.1:8000:8000
to 8000:8000
. However, if you do this, then you should also look at configuring SSL or better still running your Tryton server behind a reverse proxy such as Nginx with SSL enabled, otherwise your private information (such as your password) will cross the network in plain text.
Connect Using a Client
The client is the top tier in Tryton’s three tier architecture, and there are several clients to choose from.
The Tryton web client is provided in the Tryton Docker image and allows you to easily connect using your web browser. Your Tryton Server is accessed by visiting http://localhost:8000/ in your browser. To login you should enter admin
as the user name and then the password you entered when initializing the database.
If you have the desktop client installed, then you can use this as well. You need to enter localhost:8000
as the host, tryton
as the database, and admin
as the user name.