1

I need to run c++ application inside a docker container and it is deployed using AWS ECS. The application should run as user abcd and it should be able to generate core files. Initially I had a run script that handles enabling core files and run as abcd user. My initial run script looks like below and script is linked in docker file using CMD tag.

#!/bin/bash
echo ‘/var/dumps/core.%e.%p.%t’ | tee /proc/sys/kernel/core_pattern
ulimit -c unlimited
exec su -s /bin/bash abcd -c “myApp” 

In this case I was able to run and it was generating core files in case of crash. But when shutting down, it was not graceful because su was running as PID 1 and, once PID 1 process receives the SIGTERM, it exits first. Just after shutting down su, myApp terminates in the middle of the stopping process.

Then I referred AWS Graceful Shutdown documentation and tried to make myApp process runs as PID 1. I updated run script as below.

#!/bin/bash
ulimit -c unlimited
exec “myApp”

Also, I switched my user to abcd and enabled core patterns in docker file. Initially this case it shuts down gracefully, but it wasn’t generating core files.

Can you help me how can I achieve all three of my conditions which are,

  1. Run as abcd user
  2. Graceful shutdown
  3. Generate core files when crashing

Thank you in advance.

2
  • Please, can you provide the full Dockerfile and the ECS task definition for the container ? Commented Oct 17 at 9:40
  • It probably relates to how Bash acts differently when it's used as PID 1 in a Docker container and in a Kubernetes container. In Docker, using "bash" as the CMD is acceptable in that bash doesn't exit. However, if you run that same container in a Kubernetes environment, bash isn't persistent and the container exists. Try adding a while(true) loop or a sleep loop to the end of your exec statement. It's a klugy work-around but it'll demonstrate how the different runtimes handle Bash as PID 1. Commented Oct 19 at 2:48

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.