0

I'm trying to set up two docker containers, one is for the actual service that takes POST, PUT, DELETE, GET requests, and the second one is for an internal scheduler that will submit a POST request to the service every day.

This is my docker-compose.yml:

version: "3"

services:
  holidayservice:
    image: holiday-service:1.0
    build: .
    command: uvicorn app:app --reload --host 0.0.0.0 --port 8000
    volumes:
      - db-data:/code
    ports:
      - "8001:8000"

  scheduler:
    image: ghcr.io/umputun/cronn
    command: /srv/cronn -c "0 0 * * * /usr/bin/curl -X POST http://holidayservice:8000/holidays/ -u user:password"
    ports:
      - "27017:27017"

volumes:
  db-data:

And I have an issue with this scheduling command:

/srv/cronn -c "0 0 * * * /usr/bin/curl -X POST http://holidayservice:8000/holidays/ -u user:password"

If I connect to the terminal of the second container by running this:

docker exec -it containerID /bin/sh

and then run the scheduling command, everything works and I get no errors, I tried to change my scheduling command by putting single quotes around double quotes, etc., but either way I get an error unknown flag 'X' or invalid argument for flag -c, --command' (expected string): invalid syntax

I ran out of ideas of what else to try, please help, thank you.

Mari
  • 155
  • 1
  • 9

1 Answers1

1

The problem is the container init script (https://github.com/umputun/baseimage/blob/master/base.alpine/files/init.sh), which is buggy and poorly written. The script doesn't correctly pass on arguments containing whitespace to the exec command. If you want to run something periodically, I would just grab a regular distro image (like alpine or fedora or whatever) and use the regular cron.


Specifically, the problem is here:

if [[ ${uid} -eq 0 ]]; then
   exec su-exec app $@
else
   exec $@
fi

Using $@ without quotes is a bug; it only makes sense to use $@ in quotes, like this:

exec "$@"

This correctly maintains the argument list that was received by the ENTRYPOINT script. See e.g. this question for more details.

larsks
  • 277,717
  • 41
  • 399
  • 399