# Core dump in container

**URL:** <https://forums.docker.com/t/core-dump-in-container/43012>\
**Category:** General\
**Created:** [December 15, 2017, 6:33pm UTC](https://forums.docker.com/t/core-dump-in-container/43012 "2017-12-15T18:33:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![playbox21](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/playbox21/32/18190_2.png) [@playbox21](https://forums.docker.com/u/playbox21)\
**Post date:** [December 15, 2017, 6:33pm UTC](https://forums.docker.com/t/core-dump-in-container/43012/1 "2017-12-15T18:33:24Z")

</div>

Hi,

Our app is generating core dump files in the docker container. What is the best tool/way to debug and look inside of those files? How can I get the files down to my local machine to look inside those files?

Thanks,

---

<div class="post-metadata">

**Author:** ![wdijkerman](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/wdijkerman/32/17091_2.png) [@wdijkerman](https://forums.docker.com/u/wdijkerman)\
**Post date:** [December 17, 2017, 5:39pm UTC](https://forums.docker.com/t/core-dump-in-container/43012/2 "2017-12-17T17:39:07Z")

</div>

Make use of a volume or host mount when you start the container. Then when a core dump is created move it to the volume/host mount and then analyse it from the host.

---

<div class="post-metadata">

**Author:** ![pinkpanther2](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@pinkpanther2](https://forums.docker.com/u/pinkpanther2)\
**Post date:** [March 23, 2018, 5:44pm UTC](https://forums.docker.com/t/core-dump-in-container/43012/3 "2018-03-23T17:44:41Z")

</div>

Is there a way to configure the container to generate cores in the dedicated volume/host mount ?  
or should I write a script that scans periodically the working dir and move the cores when it finds it

Thanks

---

<div class="post-metadata">

**Author:** ![wdijkerman](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/wdijkerman/32/17091_2.png) [@wdijkerman](https://forums.docker.com/u/wdijkerman)\
**Post date:** [March 25, 2018, 5:52pm UTC](https://forums.docker.com/t/core-dump-in-container/43012/4 "2018-03-25T17:52:37Z")

</div>

Not the container, but I would say the app can be configured to where to place the core dump.

---

<div class="post-metadata">

**Author:** ![pinkpanther2](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@pinkpanther2](https://forums.docker.com/u/pinkpanther2)\
**Post date:** [March 26, 2018, 2:54pm UTC](https://forums.docker.com/t/core-dump-in-container/43012/5 "2018-03-26T14:54:26Z")

</div>

Yes, you’re right.  
I’ve found to configure the core location: [https://sigquit.wordpress.com/2009/03/13/the-core-pattern/](https://sigquit.wordpress.com/2009/03/13/the-core-pattern/)  
thanks

---

<div class="post-metadata">

**Author:** ![zerodefect](https://avatars.discourse-cdn.com/v4/letter/z/71c47a/32.png) [@zerodefect](https://forums.docker.com/u/zerodefect)\
**Post date:** [August 21, 2018, 9:58am UTC](https://forums.docker.com/t/core-dump-in-container/43012/6 "2018-08-21T09:58:05Z")

</div>

I appreciate this is a few months old.

Can I confirm that you configured the core pattern in the container **only**?

---

<div class="post-metadata">

**Author:** ![spuiu](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@spuiu](https://forums.docker.com/u/spuiu)\
**Post date:** [December 15, 2020, 3:42pm UTC](https://forums.docker.com/t/core-dump-in-container/43012/7 "2020-12-15T15:42:51Z")

</div>

I agree this is over 3 years old, with the last reply from 2 years ago, but just in case somebody stumbles upon this while searching, I’ll leave my 2 cents.

First, analyzing core dumps on the host is not a good idea, sorry. I’ve had problems taking coredumps generated in a Ubuntu 16.04 container and analyzing them in gdb on 18.04, not to mention CentOS. gdb needs to be able to find binaries and libraries involved in the process that ran, and of course libc from CentOS won’t match the one you ran with on Ubuntu. You need the same libs in order to properly analyze the core dump, so it’s best to analyze them in the container, or on a host / in a container running the same OS and libs. Also, the binary running inside the container might not be present on the host. For coredumps generated by our app in a container, I keep a container of the same OS on my machine and run gdb there to analyze it.

Also, core\_pattern is system-wide as far as I can tell, it can’t be set per container.

---

<div class="post-metadata">

**Author:** ![ext3h](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/ext3h/32/60474_2.png) [@ext3h](https://forums.docker.com/u/ext3h)\
**Post date:** [July 14, 2025, 12:07pm UTC](https://forums.docker.com/t/core-dump-in-container/43012/8 "2025-07-14T12:07:52Z")

</div>

Little script to use as a (piped) core pattern which then copies core dumps into the container that has caused them. This should be of aid for any form of CI/CD pipeline to get core dumps where they belong, but without accidentally exposing dumps belonging to different namespaces.

```bash
#!/bin/bash
# Wrapper around apport that redirects dumps into docker containers based on matching cgroup.
# Original core_pattern: |/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -F%F -- %E
# Replace apport in /proc/sys/kernel/core_pattern with this script

while getopts "p:P:" opt; do
        case $opt in
                p)
                        GUEST_PID=$OPTARG
                        ;;
                P)
                        HOST_PID=$OPTARG
                        ;;
        esac
done

CGROUP=$(cat /proc/$HOST_PID/cgroup)

container_id_list=$(docker ps -a -q)
for CONTAINER_ID in $container_id_list; do
        CONTAINER_PID=$(docker inspect -f '{{.State.Pid}}' $CONTAINER_ID)
        if [[$CONTAINER_PID -ne 0]]; then
                CONTAINER_CGROUP=$(cat /proc/$CONTAINER_PID/cgroup)
                if [["$CONTAINER_GGROUP" == "$CGROUP"]]; then
                        # Forward piped coredump into container
                        exec docker exec -i $CONTAINER_ID /usr/bin/tee /tmp/core.$GUEST_PID
                fi
        fi
done

shift 1
exec /usr/share/apport/apport "$@"

```

* * *

As long as both the container AND the host are using `systemd` there’s also the option of just sharing `/var/run/apport.socket` - but that’s not going to work out of the box and will most likely mix up containers so it’s not safe to use in a setup with concurrent containers.
