0

I've just started to use Docker.

I'm working on a project coded by another developer. In the project Docker container, I have three micro-services (aggregatore, classificatore, testmicro), each using python module logging for debugging purposes.

My issue is that I can't figure out where I can view the logging output.

docker-compose.yml

version: '2.1'
services:
  files:
    image: busybox
    volumes:
     [..]

  grafana:
     [..]

  prometheus:
     [..]

  aggregatore:
   [..] 

  classificatore:
    build: classificatore/.
    volumes:    
      - [..]
    volumes_from: 
      - files
    ports: 
      - [..]
    command: ["python", "/src/main.py"]
    depends_on: 
      rabbit:
        condition: service_healthy

  testmicro:
    [..]    
  rabbit:
    [..]

I the terminal, I run

$docker-compose up -d

this launches all the microservices.

Let's focus on classificatore service.

classificatore/Dockerfile

FROM python:3
RUN mkdir /src
ADD requirements.txt /src/.
WORKDIR /src
RUN pip install -r requirements.txt
ADD . /src/.
RUN mkdir -p /tmp/reqdoc
CMD ["python", "main.py"]

classificatore/main.py

import logging

logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)
logging.getLogger('pika').setLevel(logging.WARNING)
log = logging.getLogger()
[..]
app = Flask( __name__ , template_folder='./web')

@app.route("/")
def index(message=None):
    log.info("classificatore index!! ")
    [..]
    return render_template('index.html', files1=files1, files2=files2, message=message)

In the code above, where does the output text "classificatore index" go?

Thank you for any support you can provide.

user123892
  • 1,243
  • 3
  • 21
  • 38

3 Answers3

5

docker logs classificatore

Another way would be docker exec -it classificatore bash and then fool around in your container

zarak
  • 663
  • 1
  • 6
  • 16
  • Thank you @LeCoon. I get $ docker logs classificatore Error: No such container: classificatore/ – user123892 May 02 '19 at 13:58
  • 3
    use `docker container ps ` and check your desired container id or container name and pass it to `docker logs` command. If you want to check your logs "live" check my answer. – Michał Krzywański May 02 '19 at 14:02
  • Exactly, are you sure that you `docker-compose up -d` worked ? As @michalk said, `docker ps` will help you out finding your container. – zarak May 02 '19 at 14:03
  • Thank you @LeCoonzarakailloux, now I can see the stdout! The problem now is that Docker is not compiling my classificatore/main.py, actually I think Docker is using source files located elsewhere. I know is off-topic, I'll ask it in a new question. – user123892 May 02 '19 at 14:28
  • Please send me the link, I think I have an idea about it – zarak May 02 '19 at 14:35
  • @LeCoonzarakailloux here we are https://stackoverflow.com/questions/55955422/why-docker-is-not-compiling-my-micro-service-source-files – user123892 May 02 '19 at 15:12
3

You should modify your Dockerfile to run python script with unbuffered option.

-u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x see man page for details on internal buffering relating to '-u'

CMD ["python", "-u", "main.py"]
Alex Pliutau
  • 21,392
  • 27
  • 113
  • 143
2

As posted in other answers you can use docker logs command. Or if you want to attach your current terminal’s standard input, output, and error (or any combination of the three) to a running container, look at docker attach command. This will let you to inspect your logs "live".

Michał Krzywański
  • 15,659
  • 4
  • 36
  • 63