# Customize the Tryton Container

**URL:** https://discuss.tryton.org/t/customize-the-tryton-container/1642
**Category:** Developer
**Tags:** docker
**Created:** [August 6, 2019, 3:48pm UTC](https://discuss.tryton.org/t/customize-the-tryton-container/1642 "2019-08-06T15:48:03Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Vincenzo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/vincenzo/32/847_2.png) [@Vincenzo](https://discuss.tryton.org/u/Vincenzo)
#### Post date: [August 6, 2019, 3:48pm UTC](https://discuss.tryton.org/t/customize-the-tryton-container/1642/1 "2019-08-06T15:48:04Z")

</div>

Hi everyone,  
I’m new to the docker world.  
I’m using the tryton/tryton:4.8 containers and tryton-postgres for testing.

I have some questions:

- is it possible to make a pg\_restore on the tryton-postgres container so that it can restore an already populated database? How should to manage the owners?
- in the tryton/tryton:4.8 container can I insert custom modules instead of the standard modules?

Thanks a lot

---

<div class="post-metadata">

### Author: ![wifasoi](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@wifasoi](https://discuss.tryton.org/u/wifasoi)
#### Post date: [August 6, 2019, 10:14pm UTC](https://discuss.tryton.org/t/customize-the-tryton-container/1642/2 "2019-08-06T22:14:32Z")

</div>

> [@Vincenzo](#):
>
> s it possible to make a pg\_restore on the tryton-postgres container so that it can restore an already populated database? How should to manage the owners?

docker [exec](https://docs.docker.com/engine/reference/commandline/exec/) is you friend here (permit to launch a comand inside the contaner). You only need to have the db dumb accessible tot he container (by mounting a volume with the dump in it, or wget/curl/scp it inside). Then you can use a command like this:

```plaintext
docker exec -it containername /bin/bash

```

This will drop you in an interactive shell (so you dump and restore manually), but you can substitute the `/bin/bash` with any command you want.

> [@Vincenzo](#):
>
> - in the tryton/tryton:4.8 container can I insert custom modules instead of the standard modules?

You have two option here:

- temporary (you need to do it every time, just for testing)
- permanent (a better way IMHO)

### temporary solution

You can just exec inside the running tryton container via:

```plaintext
docker exec -it containername /bin/bash

```

then install your module manually, or via pip.  
Then update the database via the the classic

```bash
trytond-admin -u module --activate-dependencies #non the exact command

```

You should see the module after you refresh the tryton client.

### permanent solution

The better solution is to create a new docker image, but based on the tryton docker container, thi by creating a new `Dockerfile`  
(DISCAIMER: didn’t test it.. but the concept should work)

```dockerfile
FROM tryton/tryton:5.2 #change 5.2 if you want another version

RUN pip3 install mymoduleifonpypy==versionofthemodule
# you can install the module with pip3 install git+/hg+ if in a accesible version control
# otherwise you can COPY the custom module in the site-package/tryton/module folder
# or you can COPY the module folder and install it
# with RUN cd modulename && python3 setup.py install

EXPOSE 8000
VOLUME ["/var/lib/trytond/db"]
ENV TRYTOND_CONFIG=/etc/trytond.conf
USER trytond

```

then you need to build the image with docker [build](https://docs.docker.com/engine/reference/commandline/build/):

```auto
docker build . -t nameofmyimage:version
# were `.` is the path of the folder containing the Dockerfile you created
# where -t indicate the name of your image (-t is for tag)

```

if sucessfull, you can launch and configure it like the official one [[documentation page](https://hub.docker.com/r/tryton/tryton/)].  
Remember to substitute `tryton/tryton` with the name you indicated with `-t` of your new image.

!REMEMBER! the image you create with docker build is local to your computer, if you need to share it, you can [push](https://docs.docker.com/engine/reference/commandline/push/) it to a docker registry.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [August 6, 2019, 10:17pm UTC](https://discuss.tryton.org/t/customize-the-tryton-container/1642/3 "2019-08-06T22:17:55Z")

</div>

> [@Vincenzo](#):
>
> is it possible to make a pg\_restore on the tryton-postgres container so that it can restore an already populated database? How should to manage the owners?

You can run a command on an running container like this:

```
docker exec -t --user postgres tryton-postgres psql <DATABASE> < /path/db.dump

```

You will find more on the [docker postgres image](https://hub.docker.com/_/postgres) page.

---

<div class="post-metadata">

### Author: ![Vincenzo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/vincenzo/32/847_2.png) [@Vincenzo](https://discuss.tryton.org/u/Vincenzo)
#### Post date: [August 7, 2019, 1:10pm UTC](https://discuss.tryton.org/t/customize-the-tryton-container/1642/4 "2019-08-07T13:10:36Z")

</div>

Good afternoon,  
I did the pg\_restore.

If I launch tryton web I get the following error message:

> Traceback (most recent call last):  
> File “/usr/local/lib/python35/dist-packages/trytond/wsgipy”, line 71, in dispatch\_request  
> return endpoint(request, \*\*requestview\_args)  
> File “/usr/local/lib/python35/dist-packages/trytond/protocols/dispatcherpy”, line 41, in rpc  
> request, database\_name, \*requestrpc\_params)  
> File “/usr/local/lib/python35/dist-packages/trytond/protocols/dispatcherpy”, line 58, in login  
> database\_name, user, parameters, context=context)  
> File “/usr/local/lib/python35/dist-packages/trytond/securitypy”, line 31, in login  
> pool = \_get\_pool(dbname)  
> File “/usr/local/lib/python35/dist-packages/trytond/securitypy”, line 18, in \_get\_pool  
> poolinit()  
> File “/usr/local/lib/python35/dist-packages/trytond/poolpy”, line 161, in init  
> lang=lang, installdeps=installdeps)  
> File “/usr/local/lib/python35/dist-packages/trytond/modules/\_\_init\_\_py”, line 472, in load\_modules  
> \_load\_modules(update)  
> File “/usr/local/lib/python35/dist-packages/trytond/modules/\_\_init\_\_py”, line 431, in \_load\_modules  
> graph = create\_graph(module\_list)[0]  
> File “/usr/local/lib/python35/dist-packages/trytond/modules/\_\_init\_\_py”, line 158, in create\_graph  
> info = get\_module\_info(module)  
> File “/usr/local/lib/python35/dist-packages/trytond/modules/\_\_init\_\_py”, line 142, in get\_module\_info  
> with toolsfile\_open(ospathjoin(name, ‘trytoncfg’)) as fp:  
> File “/usr/local/lib/python35/dist-packages/trytond/tools/miscpy”, line 78, in file\_open  
> raise IOError('File not found : %s ’ % name)  
> OSError: File not found : /usr/local/lib/python35/dist-packages/trytond/modules/default\_value/trytoncfg

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [August 7, 2019, 1:25pm UTC](https://discuss.tryton.org/t/customize-the-tryton-container/1642/5 "2019-08-07T13:25:48Z")

</div>

You are missing the module `default_value` that was defined in your database backup.

---

<div class="post-metadata">

### Author: ![Vincenzo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/vincenzo/32/847_2.png) [@Vincenzo](https://discuss.tryton.org/u/Vincenzo)
#### Post date: [August 8, 2019, 2:17pm UTC](https://discuss.tryton.org/t/customize-the-tryton-container/1642/6 "2019-08-08T14:17:00Z")

</div>

Hi Ced,  
I managed to restore the database, I created a custom image (Tryton 4.8) by transferring my custom modules (I used the COPY method in the dockerfile).  
I have questions:

- I copied the custom modules in the path:  
`/usr/local/lib/python3.5/dist-packages/trytond/modules`  
it’s correct?

When I setup the database I get this error:

> Traceback (most recent call last):  
> File “/ usr / local / bin / trytond-admin”, line 14, in   
> import trytond.admin as admin  
> File “/usr/local/lib/python3.5/dist-packages/trytond/admin.py”, line 12, in   
> from trytond.pool import Pool  
> File “/usr/local/lib/python3.5/dist-packages/trytond/pool.py”, line 6, in   
> from trytond.modules import load\_modules, register\_classes  
> File “/usr/local/lib/python3.5/dist-packages/trytond/modules/ **init**.py”, line 10, in   
> import ConfigParser  
> ImportError: No module named ‘ConfigParser’

Why?

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [August 8, 2019, 2:44pm UTC](https://discuss.tryton.org/t/customize-the-tryton-container/1642/7 "2019-08-08T14:44:40Z")

</div>

> [@Vincenzo](#):
>
> I copied the custom modules in the path:  
> `/usr/local/lib/python3.5/dist-packages/trytond/modules`  
> it’s correct?

Normally it’s better to install the modules. Once copied you can execute:

` pip install <route_of_the_module>`

So the module is available on the path and all the dependencies are correctly installed.

> [@Vincenzo](#):
>
> Why?

Docker images use python3 and you are probably using a python2 code. Configparser is renamed to configparser in python3.
