I am trying to understand how to share logs generated by a toy project into a volume. The logs are generated inside a docker container.
For this, I am using docker-compose version 3. So far, I built the volume and the container with docker compose. However, when I check the volume I don't find any files coming from the container. Here is the project architecture:
Here is what is inside the docker-compose.yml:
version: '3'
services:
#Chatbot Service
test_bot:
build: ./test_bot
image: test_bot:1.0
#restart: always
expose:
- "5000"
ports:
- "5000:5000"
volumes:
- test_volume:/app/test_bot
# volume:
# nocopy: true
volumes:
test_volume:
networks:
negusnet:
ipam:
config:
- subnet: 172.192.10.0/16
negus.jitsi:
Here is what is inside the dockerfile.yml:
FROM python:3.6-slim
#Enviroment variables creation
ENV TEST_HOME=/app/test_bot
# Run updates, install basics and cleanup
# - build-essential: Compile specific dependencies
# - git-core: Checkout git repos
RUN apt-get update -qq \
&& apt-get install -y --no-install-recommends build-essential git-core openssl libssl-dev libffi6 libffi-dev curl nano git wget\
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# use bash always
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
#Define the path of home repository
WORKDIR ${TEST_HOME}
#Copy all files in existing negus_ai repository in docker
COPY . ${TEST_HOME}
RUN python3 ${TEST_HOME}/run_script.py
And finally, here is my test_script:
import logging
import time
logging.basicConfig(filename='Client_logs.log',
level=logging.INFO,
format='%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
if __name__ == '__main__':
i=0
while(True):
i=i+1
logging.info("yay is is "+str(i))
time.sleep(30)
[EDIT1] Just to be clear, I don't want any manipulation involving getting inside the container or having to copy manually the logs from it to the host machine.
[EDIT2] I check the container using docker container inspect id. No volumes seems to be linked to it. The mount parameter is empty.