running trac in docker containers

194 views
Skip to first unread message

Markus Rosjat

unread,
May 3, 2023, 8:44:29 AM5/3/23
to trac-...@googlegroups.com
hi all,

 i try to play around a little and hit a bump in the road with using 2 containers formy setup. I got one container for trac and one container for postgresql. So far so good, if i try to connect with python from trac container to the postgresql one i can query data as expected but if i try to run tracd it tells me it can connect to the db ... here is my pseudo connection string in my trac.ini

database = postgres://dbuser:dbpassword@dockercontainer:5432/tracdb

as i said if i pass that to psycopg2.connect as proper args i can get a cursor and fetch data. If i try to do it with trac i get
Trac Error

TracError: Unable to check for upgrade of trac.db.api.DatabaseManager: TimeoutError: Unable to get database connection within 10 seconds.
So any pointers here would be nice.

cheers

MArkus

Scott Dunt

unread,
May 3, 2023, 1:27:45 PM5/3/23
to Trac Users
I did it with mysql, but used a docker-compose file to create a network and make sure both containers shared the same network:
version: "3"
services:

TracDB:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: pass
MYSQL_DATABASE: trac
MYSQL_USER: tracuser
MYSQL_PASSWORD: pass
ports:
- "3306:3306"
command: --character-set-server=utf8 --collation-server=utf8_bin
networks:
- TracNet

Trac:
image: <your docker repos>/trac:latest
restart: always
volumes:
# Mount the data migrated here after'trac-admin /var/trac/ hotcopy /home/ubuntu/TracBackup':
- /home/ec2-user/Trac/TracBackup/:/var/trac/<sitename>/
#Had to migrate to MySQL, so 1st launch of trac container had to run this command line
# command : sh -c "sleep 5 && trac-admin /var/trac/<sitename>/ convert_db "mysql://tracuser:password@TracDB:3306/trac"
ports:
- "8088:80"
depends_on:
- TracDB
networks:
- TracNet

networks:
TracNet:

Markus Rosjat

unread,
May 3, 2023, 1:55:42 PM5/3/23
to trac-...@googlegroups.com
hey scott,

 i have a docker compose file but my tracd command doesnt seems to work, if i run int with -d flag the container restarts all the time.
Do i run the tracd command without it i get the line i posted so i am stuck at the point where both container work, i can access the db from trac container over simply python but running tracd doesnt seem to like the connection

cheers 

Markus

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/d047a9c0-cdb5-48be-a18c-3ea650cc3f47n%40googlegroups.com.

Markus Rosjat

unread,
May 3, 2023, 3:56:37 PM5/3/23
to trac-...@googlegroups.com
hi all,

so i got one step further and my docker setup is serving my trac instance now but it doesnt really solve the underlaying problem :(

so what i did is

- figure out the ip of the container
- changed my uri string in traci.ini so it uses the ip and not the docker container name

at this point my data started to get loaded but as i said this doesnt solve the problem, i want to be able to use a hostname for obvious reasons. 
So how do i make trac aware that it needs to resolve my container name correctly? I mean for my simply testscript its not a problem but trac cant do it,
i hope we get something to work here.

here is my simply script that works just as expected ...

import psycopg2

conn = psycopg2.connect(
    "postgres://dbuser:dbpassword@trac-postgresql:5432/trac_db"
)
cur = conn.cursor()
cur.execute("SELECT * FROM ticket;")
rows = cur.fetchall()
for row in rows:
    print(row)

cheers 

MArkus

Jun Omae

unread,
May 3, 2023, 9:20:07 PM5/3/23
to trac-...@googlegroups.com
On Wed, May 3, 2023 at 9:44 PM Markus Rosjat <markus...@gmail.com> wrote:
>
> hi all,
>
> i try to play around a little and hit a bump in the road with using 2 containers formy setup. I got one container for trac and one container for postgresql.

You should share your docker-compose.yml if you want advice and supports.

> So far so good, if i try to connect with python from trac container to the postgresql one i can query data as expected

How did you execute query to verify it? Please provide commands which you tried.

> but if i try to run tracd it tells me it can connect to the db ... here is my pseudo connection string in my trac.ini
>
> database = postgres://dbuser:dbpassword@dockercontainer:5432/tracdb

Try to use "localhost" instead of "dockercontainer".


--
Jun Omae <jun...@gmail.com> (大前 潤)

Markus Rosjat

unread,
May 4, 2023, 1:55:27 AM5/4/23
to trac-...@googlegroups.com
hey jun,

my yml file:

version: '3'
services:
  trac:
    build:
      context: .
      dockerfile: trac.Dockerfile
    container_name: trac
    command: tracd --auth="*,/var/trac/auth/tracauth,testtrac" -p8000 --base-path=/testtrac -s /var/trac/projects/testtrac
    ports:
      - 8000:8000
    volumes:
      - .:/var/trac
    depends_on:
      - postgresql
    networks:
      - trac-network

  postgresql:
    build:
      context: .
      dockerfile: postgresql.Dockerfile
    container_name: trac-postgresql
    ports:
      - 5432:5432
    restart: always
    environment:
      POSTGRES_PASSWORD: secret
    networks:
      - trac-network
networks:
  trac-network:

my test script again that can query the db in the postgresql container

import psycopg2

conn = psycopg2.connect("postgres://dbuser:dbpassword@trac-postresql:5432/trac_db")
cur = conn.cursor()
cur.execute("SELECT * FROM ticket;")
rows = cur.fetchall()
for row in rows:
    print(row)
using localhost, well i dont see how this will work even docker handles 2 containers as 2 different machines but for the sake of argument i changed my trac.ini back an got the expected result. With localhost in the uri 
I am back at the point that trac cant reach the db container.

cheers

MArkus 

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+...@googlegroups.com.

Markus Rosjat

unread,
May 5, 2023, 3:49:58 AM5/5/23
to trac-...@googlegroups.com
Hi all,

i guess i solved the mystery around the problem. I took a look at scoots yml file and saw something that got me thinking and i changed it accordingly in my file. I had the property container-name set and i removed it. Then i changed my uri to use the service name and rebuild my images. After that the connection started working as expected. 

Conclusion: 

Dont set a container-name in the docker-compose file.


Cheers

Markus

Markus Rosjat

unread,
May 5, 2023, 9:41:56 AM5/5/23
to trac-...@googlegroups.com
hi all,

on last question about the whole setup. I use command to start tracd in foreground since otherwise the container would quit if i run it with -d flag. 
So is this ok to do or should i try to work somehow around this and put tracd in the background ?

cheer

Markus 

Am Do., 4. Mai 2023 um 07:55 Uhr schrieb Markus Rosjat <markus...@gmail.com>:

Jun Omae

unread,
May 5, 2023, 10:13:21 AM5/5/23
to trac-...@googlegroups.com
On Fri, May 5, 2023 at 10:42 PM Markus Rosjat <markus...@gmail.com> wrote:
>
> hi all,
>
> on last question about the whole setup. I use command to start tracd in foreground since otherwise the container would quit if i run it with -d flag.
> So is this ok to do or should i try to work somehow around this and put tracd in the background ?
>
> cheer
>
> Markus

I'm not sure what you're worried about, but I think tracd in foreground is okay.
However, I'd use apache + mod_wsgi rather than tracd in the first place.

Markus Rosjat

unread,
May 5, 2023, 10:16:36 AM5/5/23
to trac-...@googlegroups.com
I am not worried just wondering, I run an Apache as webserver at the moment and do,rewrites to the tracd. 

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages