0

community!

I developed a few services in python that are supposed to communicate via rabbitmq. Python scripts look correct. Event after I moved them to docker containers, they continue look working ('Waiting for messages' line is generated by the payload script):

grafalex@debian:~/Work/partitioner/worker$ docker run -it --network partitioner_pocnetwork worker:latest
 [*] Waiting for messages. To exit press CTRL+C

The issue is that once I am running the same through docker-compose I can no longer see any logs. Sometimes part of the log may appear in the console, but just a part.

grafalex@debian:~/Work/partitioner/worker$ docker-compose up worker1
Starting partitioner_worker1_1 ... done
Attaching to partitioner_worker1_1

Here is the docker-compose.yml snippet for this

version: "3.9"
services:
  worker1:
    image: worker:latest
    restart: always
    networks:
      - pocnetwork
...
networks:
  pocnetwork:

What can be the problem with missing logs? Can it be some kind of stdout buffering (and if so how can I fix that)?

  • Not sure, but do you need network access for the logs to show? With docker run you are using --network partitioner_pocnetwork. Did you create this network beforehand with docker network create? If yes, you need to import this network in your docker-compose.yml at the bottom, like: networks: pocnetwork: external: name: partitioner_pocnetwork see this link at the bottom https://docs.docker.com/compose/networking/ – nulldroid Aug 31 '21 at 20:54
  • Is your problem that [Python app does not print anything when running detached in docker](https://stackoverflow.com/questions/29663459/python-app-does-not-print-anything-when-running-detached-in-docker)? Can you edit the question to include a [mcve], not just the one fragment of the Compose setup but enough to demonstrate the problem? – David Maze Sep 01 '21 at 00:12
  • Yes, I have networks section in my docker-compose.yml. I edited the question to reflect this. And this network was already created by docker-compose when I tried running the container with pure docker. The network operates in the bridge mode, it has access to the internet, as well as other containers. I do not have concerns about network setup – Oleksandr Masliuchenko Sep 01 '21 at 11:06
  • @DavidMaze, you were right. The problem was in the bufferred python output. Thank you for pointing to the right solution. – Oleksandr Masliuchenko Sep 01 '21 at 11:18

2 Answers2

2

The problem is not related to networking. The problem is in buffered output. As @DavidMaze pointed in the comment, solution is well described in Python app does not print anything when running detached in docker.

I just had to add '-u' flag to the python interpreter to make the output unbuffered, so that it appears in the log immediately.

0

Since you seem to be using a pre-existing docker network, the equivalent to your docker run command in docker-compose should look like:

  worker1:
    image: worker:latest
    restart: always
    networks:
      - pocnetwork
  networks:
    pocnetwork:
      external: true
      name: partitioner_pocnetwork

You need to declare the external network first. Does this solve your problem?

nulldroid
  • 1,150
  • 8
  • 15
  • I am using the network created by docker-compose. I edited my question to reflect this. Perhaps no need to set external: true, as I would like docker-compose to create the network for me. As I said I do not have issues with the network itself - everything works normally, container can connect to the network, as well as to other containers in the same network. They even communicate somehow. The issue is that I can't see any logs in the console (despite the fact the container is working, and sending messages) – Oleksandr Masliuchenko Sep 01 '21 at 11:12