I need to develop my app while it is running in a docker container. I've tried a few things that I can elaborate on but before I do I would like to ask if there is a recommended way to do repl driven development with the project running in a docker container.
I’m not able to answer with any tips here right now. But tonight I can share what little I know about it. Hopefully others will have beaten me to it!
I'm looking forward to the Joyride presentation!
I tried the following.. deps.edn:
{
...
aliases {
:repl/headless {:extra-deps {nrepl/nrepl {:mvn/version "1.3.1"}
cider/cider-nrepl {:mvn/version "0.40.0"}}
:main-opts ["--main" "nrepl.cmdline"
"--middleware" "[cider.nrepl/cider-middleware]"
"--port" "50000"]}
}
}
Dockerfile:
FROM clojure:tools-deps-trixie-slim
WORKDIR /app
COPY src /app/src
COPY deps.edn /app/deps.edn
EXPOSE 50000
ENTRYPOINT ["clj", "-M:repl/headless"]
docker-compose.yml:
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- 50000:50000
volumes:
- .:/app
Once the container is running I try to connect to the REPL at localhost:50000 from Calva but then I get the following error:
Connecting ...
Reading port file: file:///Users/garfield/dev/clojure/my-app/.nrepl-port ...
Using host:port localhost:50000 ...
Hooking up nREPL sessions ...
nREPL connection failed: Error: read ECONNRESET
Failed connecting.From the container output I can see that the REPL server is running:
app-1 | nREPL server started on port 50000 on host localhost - You probably need to specify the host as 0.0.0.0 when starting the repl.
Ah, thank you. I added --bind 0.0.0.0 to deps.edn and now it works.
{
...
aliases {
:repl/headless {:extra-deps {nrepl/nrepl {:mvn/version "1.3.1"}
cider/cider-nrepl {:mvn/version "0.40.0"}}
:main-opts ["--main" "nrepl.cmdline"
"--middleware" "[cider.nrepl/cider-middleware]"
"--bind" "0.0.0.0"
"--port" "50000"]}
}
}VsCode and therefore Calva support "remote development" in a container. So you can "connect" to the container and then all works as expected. This expects the code being in the container as well, not sure this fits your setup.
Thank you Carsten. I will try that option out as well.