Custom container command in AWS ECS tasks

I recently made the switch from Heroku to AWS ECS and customizing the command for the task containers was one of the things I had more trouble with.

This is my Procfile that I'm trying to convert to ECS task definitions:

web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -C config/sidekiq.yml

The CMD of my docker image starts the web process by default and when I created the task definition for the web process it worked like a charm.

Now it's the turn of the worker process to use the same docker image but overriding the default docker CMD so I did this in my task container definition:

The wrong way to specify ECS task container command

I created the worker service in my cluster using this worker task definition and everything goes wrong:

container_linux.go:247: starting container process caused "exec: \"bundle exec sidekiq -C config/sidekiq.yml\": stat bundle exec sidekiq -C config/sidekiq.yml: no such file or directory"

I'm pretty sure the command is inside the docker image since I can run it with docker exec, what the help tip for the command field says?

ECS task tooltip

Ok sure, here are some examples taken from the documentation for Docker CMD:

  • CMD ["executable","param1","param2"] (exec form, this is the preferred form)
  • CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
  • CMD command param1 param2 (shell form)

So I should be able to use all three ways to represent my command, so that can't be the issue.

I switch to JSON mode and find our that the command is actually an array:

"command": [
                "bundle exec sidekiq -C config/sidekiq.yml"

So it probably means the first element in the array is the executable and the rest are arguments.

So I changed in JSON to use multiple arguments and wala!

The right way to specify ECS task container command with commands

It's freaking comma-separated!!! After that the service was able to start correctly.

Guess what, the placeholder in the text box has specific instructions to use commas, but who checks other ways to enter the command when amazon explicitly states that you should be checking Docker CMD documentation for instructions.

What a horrible User Experience.