'ECS Task Definition - When overriding ENTRYPOINT, Docker image's CMD is dropped

I have a Docker Image built with the following CMD

# Dockerfile
...
CMD ["nginx", "-g", "daemon off;"]

When my task definition does not include entryPoint or command the task successfully enters a running state.

{
  "containerDefinitions": [
    {
      "image": "<myregistry>/<image>",
      ...
    }
  ]
}

I need to run an agent in some instances of this container, so I am using an entrypoint for this task to run my agent. The problem is when I add an entryPoint parameter to the task definition, the container starts and immediately stops.

This is what I'm doing to add the entryPoint:

{
  "containerDefinitions": [
    {
      "image": "<myregistry>/<image>",
      ...
      "entryPoint": [
        "custom-entry-point.sh"
      ],
    }
  ]
}

And here is the contents of custom-entry-point.sh:

#!/bin/bash
/myagent &
echo "CMD is: $@"
exec "$@"

To confirm my suspicion that CMD is dropped, the logs just show:

CMD is: 

If I add the CMD array from the Dockerfile to the task definition with the command parameter, it works fine and the task starts:

{
  "containerDefinitions": [
    {
      "image": "<myregistry>/<image>",
      ...
      "entryPoint": [
        "custom-entry-point.sh"
      ],
      "command": [
        "nginx",
        "-g",
        "daemon off;"
    }
  ]
}

And the logs show the expected:

CMD is: nginx -g daemon off;

I have many docker images with various iterations of CMD, I do not want to have to copy these into my task definitions. It seems that just adding only an entryPoint to a task definition should not override a docker image's CMD with an empty value.

Hoping some ECS / fargate experts can help shed some light on a path forward.



Solution 1:[1]

Some tips:

  1. Check if your entrypoint script is executable
  2. Use absolute path to your entrypoint script
  3. Check logs to see the error. hopefully you autoconfigured awslog driver?
  4. Have you successfully run the entrypoint version on your local?

Also have a read of this for some useful background: https://aws.amazon.com/blogs/opensource/demystifying-entrypoint-cmd-docker/

Solution 2:[2]

I got the same problem, with my entrypoint and command attributes being something like sh -c .... I needed to delete sh -c, put the commands directly, and add #!/bin/sh at the top of my scripts.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stephen Ostermiller
Solution 2 Tony