I try to dockerize a PyQt Application that connect to a containerized MariaDB server using mysqlalchemy. I am completely new to docker. With help on the Qt forum it seems that I could manage to make my app container communicate with the MariaDB container. My residual problem is how to connect to the X11 server? I found some hints in this question on stackoverflow but when I use this solution, I get the following message
sudo docker-compose run app [sudo] Mot de passe de jaaf : Creating network "project_default" with the default driver Creating mydb2 ... done Creating project_app_run ... error
ERROR: for project_app_run Cannot create container for service app: conflicting options: host type networking can't be used with links. This would result in undefined behavior
ERROR: for app Cannot create container for service app: conflicting options: host type networking can't be used with links. This would result in undefined behavior ERROR: Encountered errors while bringing up the project.
I must add that my system is Fedora 38 using X11 not wayland.
How can I resolve this conflict as I have to connect both to MariaDB and to the X11 server?
Hereafter are the relevant files
docker-compose.yml
version: "3"
volumes:
data:
services:
db:
container_name: mydb2
image: mariadb:latest
ports:
- "32001:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: root
volumes:
- data:/var/lib/mysql
app:
container_name: biere
links:
- "db"
build: ./
environment:
- DISPLAY=$DISPLAY
- QT_DEBUG_PLUGINS=1
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
- ~/.Xauthority:/root/.Xauthority
ports:
- "5001:5000"
network_mode: "host"
Dockerfile
FROM fedora:38
ENV DISPLAY=:0
COPY . .
RUN dnf -y upgrade
RUN dnf -y install python3 python3-pip
RUN python3 -m pip install -r dependencies.txt
RUN dnf install -y mesa-libGLU libxkbcommon libxkbcommon-x11 mesa-libEGL fontconfig dbus-libs xcb-util-cursor xcb-util-wm xcb-util-keysyms xauth
CMD [ "python3", "main.py" ]
db_connection.py
from sqlalchemy import create_engine
from sqlalchemy_utils import create_database, database_exists
from sqlalchemy.orm import sessionmaker, scoped_session
from database.orm_base import Base
db_url="mysql+pymysql://root:root@mydb2:3306/a_db"
if not database_exists(db_url):
create_database(db_url)
engine = create_engine(db_url,pool_size=5,pool_recycle=3600)
Session =sessionmaker(bind=engine,expire_on_commit=False)
session =Session()