I have an application that uses docker compose to start 3 containers. The logs for those 3 containers are outputted to stdout as expected. One of these containers is responsible for starting other containers, as they are needed. It uses docker-py to do that.
Those secondary containers are ephemeral, they run until the task is done and terminate. However I can't see their logging output.
- When I started, the
docker-composecontainers also weren't outputting logging tostdout, I had to use the following configs both inDockerfileand the code:
self.logger = logging.getLogger(__name__)
level = logging.INFO
stream_handler = logging.StreamHandler(sys.stdout)
self.logger.setLevel(level)
formatter = logging.Formatter("%(asctime)s - %(name)s [%(levelname)s]: %(message)s")
stream_handler.setFormatter(formatter)
self.logger.addHandler(stream_handler)
Dockerfile
ENV PYTHONUNBUFFERED=1
Now, I've tried to add the same settings in the code and Dockerfile for my secondary containers, this time though, it made no difference. It's possible that I may need to pass further instructions to docker-py when running the containers.
network = self.docker_client.networks.get("service-daemon_default")
_ = self.docker_client.containers.run(
image="default_image",
detach=True,
environment={
"VENDOR_NAME": vendor,
**self.settings.get("environment"), # These are just REDIS configs, such as host, port , etc
},
name=vendor.lower(),
network=network.name,
auto_remove=self.settings.get("auto_destroy_containers", True),
)