2

I'm building some software with docker-compose, for which I would like to run on a schedule.

So I need to schedule a run of docker-compose up, on MacOS (High Sierra, 10.13.3), using launchd. This is the LaunchAgent configuration I'm using.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>local.edgarlydata</string>

    <!-- This script, which calls "docker-compose up" also fails :/

    <key>Program</key>
    <string>/Users/me/my/project/my-script.sh</string> -->

    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/bin/docker-compose</string>
      <string>up</string>
    </array>

    <key>StartCalendarInterval</key> 
    <array>
      <dict> 
        <key>Hour</key> 
        <integer>19</integer> 
        <key>Minute</key> 
        <integer>18</integer> 
        <key>Weekday</key>
        <integer>3</integer>
      </dict>
    </array>
  </dict>
</plist>

And when the process is launched at the scheduled time, the system log gives me this error message. There's no reason as to why the failure is happening.

Aug 15 19:18:00 MacBook-Pro com.apple.xpc.launchd[1] (local.edgarlydata[5379]): Service exited with abnormal code: 1

EDITED to add contents of a try with /Users/me/my/project/my-script.sh. No dice.

#!/bin/sh

sudo -u myuser /usr/local/bin/docker-compose up

I saw a similar question here. But that was for docker-machine. docker-compose needs to start from a project directory. Needless to say, it doesn't solve the problem.

Any ideas?

  • I don't know launchd, but I don't see anywhere the working directory, and your script doesn't cd. Are you sure you're in a directory with a docker-compose.yml when this runs? – user2313067 Aug 16 '18 at 5:55
0

Ideally, the contents of /Users/me/my/project/my-script.sh

Should just be:

docker compose up

And the majority of your Docker configuration should go inside your project's docker-compose.yml file.

  • I've edited the question to include the contents of that try with my-script.sh. That doesn't work either. – Nutritioustim Aug 16 '18 at 3:43
0

So I got this working, first by specifying the StandardErrorPath and StandardOutPath. Those logs let me see that there was an error in my docker-compose working_dir setting. It was previously docker's PWD, and I hard-coded it to just /usr/app

app:
  image: my/app:latest
  working_dir: /usr/app
  volumes:
    - .:/usr/app
  entrypoint: run app

My myjob.plist now looks like this. And this is working for me. Hope this helps others.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>local.myjob</string>

    <key>StandardErrorPath</key>
    <string>/Users/me/Projects/myproject/stderr.log</string>

    <key>StandardOutPath</key>
    <string>/Users/me/Projects/myproject/stdout.log</string>

    <key>WorkingDirectory</key>
    <string>/Users/me/Projects/myproject</string>

    <key>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
    </dict>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/bin/docker-compose</string>
      <string>up</string>
      <string>-d</string>
    </array>

    <key>StartCalendarInterval</key> 
    <array>
       <dict> 
        <key>Hour</key> 
        <integer>9</integer> 
        <key>Minute</key> 
        <integer>30</integer> 
        <key>Weekday</key>
        <integer>1</integer>
      </dict>
    </array>
  </dict>
</plist>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.