Debugging Docker on CI/CD

How To Enter A Docker Container From CI/CD-Pipeline Build Job

How To Enter A Docker Container From CI/CD-Pipeline Build Job

Introduction

It is by now a normal setup to have the build agents on a CI/CD-pipeline (e.g. TeamCity) using Docker containers to quick and easily create the environments required to run a desired build step. 

Therefore, it is also normal that these Docker containers require some debugging when setting up the build steps. 

This is a short guide for how to enter a docker container with the exactly same environment as the build agent (e.g. work directory and environmental variables.)

Step 1: Find information from (failed?) build

Find the build job, which you would like to investigate. We are intending to enter that specific build job’s work
folder to have the exact same configurations.

When the build job has been found, we enter the “Build
log” and find the intended build step. Different build steps may use different Docker containers.

Step 2: Extract Docker snippets

We need to extract the following snippets from the build log’s “Docker initialization”-section:

  • Volume: A declaration working folder will be attached to the Docker container and therefore available within the container. This is relevant to reproduce the exact same conditions as the CI/CD-pipeline.
    Should look something like this:
				
					-v "/home/build-agent/BuildAgent/work/deb42684ec7d874e:/home/build-agent/BuildAgent/work/deb42684ec7d874e"
				
			
  • Entrypoint: The entrypoint is the reference to the Docker image.
    Should look something like this: 
				
					--entrypoint “puppeteer:8.0.0"
				
			

Step 3: Create Docker command

With the extractions from step 2, we are now able to create a Docker command to enter the container with the build job’s work folder.

The command should be structured as stated below. The command includes the two snippets from step 2, with the addition of “docker run -it”, at the start of the command, and “/bin/bash”, at the end of the command. (if bash is not included it will run as “/bin/sh” by default).

				
					docker run -it -v "/home/build-agent/BuildAgent/work/deb42684ec7d874e:/home/build-agent/BuildAgent/work/deb42684ec7d874e" –entrypoint “puppeteer:8.0.0" /bin/bash
				
			

Recommended Reading

About

Hi, I'm the Author

My name is Daniel H. Jacobsen and I’m a dedicated and highly motivated software developer with a masters engineering degree within the field of ICT. 

I have through many years of constantly learning and adapting to new challenges, gained a well-rounded understanding of what it takes to stay up to date with new technologies, tools and utilities. 

The purpose of this blog is to share both my learnings and knowledge with other likeminded developers as well as illustrating how these topics can be taught in a different and alternative manner.

If you like the idea of that, I would encourage you to sign up for the newsletter.

Cheers! 🍺

Didn't Find What You Were Looking For?

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Scroll to Top
INTEGU - Cookie-consent

INTEGU uses cookies to personalize your experience and provide traceability for affiliate links. By using the website, you agree to these terms and conditions. To learn more see the privacy policy page.