question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docker-Compose logging to variable

See original GitHub issue

Required Information

Entering this information will route you directly to the right team and expedite traction.

Question, Bug, or Feature?
Type: Feature/Question

Enter Task Name: Docker-Compose

list here (V# not needed): 0 https://github.com/Microsoft/azure-pipelines-tasks/tree/master/Tasks

Environment

  • Server - Azure Pipelines or TFS on-premises? Azure Pipeline

    • If using Azure Pipelines, provide the account name, team project name, build definition name/build number: N/A
  • Agent - Hosted or Private: Hosted agent

    • If using Hosted agent, provide agent queue name: N/A
    • If using private agent, provide the OS of the machine running the agent and the agent version: N/A

Issue Description

I’m trying to build a script that is able to cache images even on a Hosted Agent. Something similar to this: https://github.com/marketplace/actions/build-docker-images-using-cache and https://testdriven.io/blog/faster-ci-builds-with-docker-cache/

However for this to nicely integrate into Azure DevOps I would like to be able to read out the created identifiers per stage. This can be done quite easily by reading through the log file. E.g.:

image

In the image above I want to get the Id so that I can execute a docker tag afterwards and tag this specific image as something like devemazegenerator-stages:0

So my main question would be, if it’s possible to somehow storage all logging to a variable during a docker-compose build or docker build.

Regarding directly targeting a stage instead

So in regards to directly targeting a stage instead, like for example calling:

docker build . --stage build

I first thought about using this, but the issue here is that you’re basically doing a docker build twice. I would like to be able to kick-off docker-compose, have all variables / configuration setup there and then afterwards pick-up the stages that I want to push to the registry.

Next to that, it currently seems to be impossible to target an unnamed stage. See: https://forums.docker.com/t/docker-build-first-stage-in-multi-stage-pipeline/91167

Task logs

N/A

Troubleshooting

N/A

Error logs

N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
devedsecommented, Apr 7, 2020

Another update, I just found out that apparently the lines Building .... are being written to STDERR. I’ve created a bug report for that:

https://github.com/docker/compose/issues/7346

0reactions
thesattirajucommented, Apr 13, 2020

@ds-ms, how would you pipe the output to an environment variable that can be used in a follow up task? I’ve been reading through the documentation but what I’ve only found is this:

If you want to share the contents within a job, you could simply pipe the logs to a file. And use that file path in your scripts within the job.

I checked with @azooinmyluggage, I’ll take your PR forward; it seems like a good addition. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure logging drivers - Docker Documentation
Use environment variables or labels with logging drivers . Some logging drivers add the value of a container's --env|-e or --label flags...
Read more >
Docker Compose: Log output to both a file and stdout
I've heard a best practice : Logs are to be treated as a stream. the app itself should not manage logging (redirections, storage,...
Read more >
Configuring Docker environments - AWS Elastic Beanstalk
Docker container customized logging (Docker Compose) · ${EB_LOG_BASE_DIR} is an environment variable set by Elastic Beanstalk with the value /var/log/eb-docker/ ...
Read more >
Environment variables in Compose - Docker - the Docs
The value of the DEBUG variable in the container will be taken from the value for the same variable in the shell in...
Read more >
Docker Logging: 101 Guide to Logs, Best Practices & More
The importance of logging applies to a much larger extent to Dockerized applications. When an application in a Docker container emits logs, they...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found