docker / docker/docker-py

Get STDOUT and STDERR from the docker run command in different files.

Open
#2,141 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.2k
Forks
1.7k
Avg merge
13d 8h
Merged PRs (30d)
2

Description

I have python script who's responsibility is to run docker image. For running the docker image I am using docker client and the run command is defined like this -

def run_docker(self, cred, image, env, volumes, cmd):
    """
    Docker image needs to be executed after image is successfully pulled,
    and docker command is contructed based on the job parameters.
    """

    self.log.info('run_docker', state=self.state)
    self._docker_login(cred)
    self.docker_client = docker.from_env()
    self.container = self.docker_client.containers.run(
                                            image,
                                            environment=env,
                                            volumes=volumes,
                                            command=cmd,
                                            stderr=True,
                                            remove=True,
                                        )

There are two problems -

  1. When you remove the container the docker log file which captures the STDOUT and STDERR together is also removed.
    Because of this issue, I decided to write STDOUT and STDERR to two different files, so that the user gets to analyse STDERR and STDOUT with maximum flexibility.

While using the docker client as mentioned here -
https://docker-py.readthedocs.io/en/stable/containers.html
The parameters have been modified accordingly in the run command.
But I am unable figure out how to accomplish this.
Also docker client doesn't mention how to use logging plugins.

Any help or suggestions are welcome.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the containers.run call shown in the issue and read the Docker Engine API and docker-py documentation for its stdout, stderr, remove, and logging options. Investigate how logging plugins are exposed by the client. Done means establishing whether separate stdout and stderr files are supported and documenting or implementing the supported approach.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
devops
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.