0

I want to run 3 Docker containers and start a simple programm.

  • Python
  • Postgres
  • Adminer

I'm using docker-compose and dockerfiles to run and build all these containers. Everything work well until I want to start a GUI in my Python app. I'm using Tkinter and Plot to show my Application, but every time I'm starting the docker-compose file, I get a error like:

_tkinter.TclError: couldn't connect to display "unix:1"

You can see the files below:

docker-compose.yml

version: '3.1'

services:
  mypython:
    container_name: tsp_python
    build:
      context: .
      dockerfile: ./config/python/Dockerfile
    depends_on:
      - db
      - adminer
    volumes:
      - /tmp/.X11-unix:/tmp/.X11-unix:rw
    environment:
      DISPLAY: unix$DISPLAY

  db:
    container_name: tsp_postgres
    image: postgres:11
    build:
      context: .
      dockerfile: ./config/postgres/Dockerfile
    restart: always
    ports:
      - 5432:5432
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: ${DB_NAME}
      POSTGRES_PASSWORD: ${DB_USER}
      POSTGRES_USER: ${DB_PASSWORD}

  adminer:
    container_name: tsp_adminer
    image: adminer
    restart: always
    ports:
      - 8080:8080
    depends_on:
      - db

volumes:
  db-data:

The python Dockerfile:

FROM python:3.7.3

WORKDIR /code

RUN pip3 install --upgrade pip

COPY ./require.txt .
RUN pip install -r require.txt

COPY /src .

ENV PYTHONPATH "${PYTHONPATH}:/code"

EXPOSE 5432/tcp

CMD ["python", "__main__.py"]
  • Does this answer your question? [Python Tkinter in Docker .TclError: couldn't connect to display](https://stackoverflow.com/questions/39445047/python-tkinter-in-docker-tclerror-couldnt-connect-to-display) – jasonharper Oct 13 '20 at 13:05
  • No, that doesnt work for me, but I fixed it. Thanks for your comment :) I need a permission to x Server, so I run the following code: xhost +local:root – Viet Hung Tran Oct 13 '20 at 14:39

0 Answers0