Ocaml Dockerfile - Permission denied on `opam exec -- dune build`

Hi Fly team,

I’m attempting to deploy an Ocaml Dream web framework app.. It runs a Dockerfile - the example app can be found here. I’m new to the OCaml system, so the error below may be related to Opam (Ocaml package manager) or Dune (Ocaml build system).

Error:

Step 7/11 : RUN opam exec -- dune build
 ---> Running in 40ac6ec60c9a
Error: _build/log: Permission denied

Error error building: error rendering build status stream: The command '/bin/sh -c opam exec -- dune build' returned a non-zero code: 1

This error also occurs on Render.com, so I’m led to believe it’s likely due to Opam attempting to write files where it can’t. Any intuition here or workarounds?

I am considering building the executable locally and then just having Fly run that.

This might happen if that directory doesn’t exist. Try adding this on line 7 of your Dockerfile:

RUN mkdir -p _build/log

If that works, you might want to look at opam logging options. It would be much better to print that build log to stdout if possible. There’s probably setting for that but 3 minutes of googling didn’t turn it up yet. :slight_smile:

1 Like

Can you let me know which Docker version you’re running? I was able to deploy the example without a problem, and also could build locally. Does docker build -t dream-example . work for you?

1 Like

I just successfully deployed the example itself too @ https://autumn-flower-9623.fly.dev. Very strange, but wow this is so cool! My first Fly app.

I’ll debug some more and see what the difference is. Some things to look into:

  1. diff the example and my own code. I do apologize for misleading, but this is the actual code I’m deploying. It’s only lightly built upon the example. A big difference I see is that I’m connecting to a local Postgres, and not account for a deployed instance. But I wouldn’t have expected the app to break at build time.

  2. tweak opam logging

I found the issue. Thank you @Joshua @kurt .

I missed the .dockerignore, and the image itself already had an existing _build folder. Removing the build allowed me to launch the build fine. I’ll add the ignore file now. Things are building fantastically.

Great! We can add this to our list of builders to add to fly launch.

1 Like