Fork me on GitHub
#docker
<
2020-04-08
>
Spaceman14:04:53

Hi, I have the following Dockerfile:

Spaceman14:04:09

and I'm trying to deploy on heroku

Spaceman14:04:19

but I get the error that clojure.main not found.

Spaceman14:04:11

even when running locally using: docker build -t test . and docker run -ti test I get the same error

lispyclouds15:04:50

How did you build the jar file?

Spaceman20:04:16

The jar file wasn't built. Here's the updated Dockerfile. But the lein uberjar command doesn't work. I get project.clj not found.

lispyclouds20:04:31

you need to add the project files i think? a COPY . . is needed before the lein command

lispyclouds20:04:54

docker builds in an isolated environment, you need to add the files otherwise it has no idea of the files in the directory.

👍 4
Spaceman20:04:32

I was able to deploy it but it says "started on localhost:5000" on remote?

lispyclouds20:04:12

so you need to mount this port outside the container to access it

lispyclouds20:04:37

you need a -p 5000:5000 with the run command

lispyclouds20:04:17

also it may not be reachable from the outside as its listening to only localhost

lispyclouds20:04:52

If you are new to docker, i could recommend some docker resources first, should help you get docker specific issues sorted first? 🙂

Spaceman20:04:59

sure thanks!

lispyclouds20:04:51

this goes through a nodejs setup with a server and mounting ports and has a nice explanation of why is what

lispyclouds20:04:27

i would recommend try this out and get a feel of docker and the clojure thing should be simple after it 🙂

Spaceman20:04:31

the -p 5000:5000 with RUN java $JVM_OPTS -cp target/vendo.jar clojure.main -m vendo.application -p 5000:5000 didn't change anything.

lispyclouds20:04:09

this needs to happen outside with the docker run -p 5000:5000 ...

lispyclouds20:04:31

this happens in 2 steps: - build the image - run with port and volume mounts

lispyclouds20:04:11

again, i really recommend to try the tutorial first, getting the docker concepts first would really help

lispyclouds20:04:05

mixing the clojure and docker issues together would make it a bigger mess i'd say

lispyclouds20:04:57

also this seems nice for a clojure app on docker: https://roboloco.net/blog/clojure-apps-in-docker/

lispyclouds20:04:49

some basic networking know how may be needed to access it properly, I can help out if you face issues then 🙂

👍 4
Spaceman20:04:22

I'm simply deploying the app using git push heroku master

Spaceman20:04:31

And the docker stuff seems to happen automatically

Spaceman20:04:45

How to add the -p 5000:5000... option then?

lispyclouds20:04:11

so 2 things i guess: - you need to EXPOSE the port from docker. you would need a EXPOSE 5000 as one of the lines on the Dockerfile - the app needs to listen to 0.0.0.0:5000 and its only listening to localhost now i think

lispyclouds20:04:39

the second part depends on the app config, not sure where to change that, its app specific

Spaceman21:04:34

It says • EXPOSE - While `EXPOSE` can be used for local testing, it is not supported in Heroku’s container runtime. Instead your web process/code should get the $PORT environment variable.

lispyclouds21:04:57

yes, your app should read this and listen to this port

lispyclouds21:04:08

this seems to be how heroku works

lispyclouds21:04:15

also your app needs to listen to 0.0.0.0 or all interfaces, its listening on 127.0.0.1 i think. https://serverfault.com/questions/78048/whats-the-difference-between-ip-address-0-0-0-0-and-127-0-0-1

lispyclouds21:04:06

this is the networking thing i was telling about

👍 4
lispyclouds21:04:14

just making your app listen on 0.0.0.0 should make this work i think :thinking_face:

Spaceman21:04:33

But I don't know what gunicorn means

lispyclouds21:04:17

this is a python server, not relevant here i think

lispyclouds21:04:49

is your code online somewhere? maybe i can have a look?

lispyclouds21:04:42

i feel docker here is adding more complexity

Spaceman21:04:07

it's because I need python in my app

lispyclouds21:04:01

can i see the myapp.application namespace?

lispyclouds21:04:14

need to know how you listen

Spaceman21:04:30

these are all the relevant files I think

lispyclouds21:04:28

okay looks like its listening on 5000 with aleph, does it deploy successfully? and youre able to ping it?

Spaceman21:04:56

Yes it deploys successfully

lispyclouds21:04:36

are you able to reach it from the heroku url?

lispyclouds21:04:51

it should be i think if the port is correct

Spaceman21:04:56

no, it says application error

lispyclouds21:04:37

does it have any more logs? like is it from heroku or the app?

lispyclouds21:04:50

also if possible you could paste your app public URL here too?

lispyclouds21:04:55

will have a look tomorrow if still not solved! getting late here, ta! good luck 🙂

Spaceman15:04:30

I changed the last command to: RUN java $JVM_OPTS -cp target/myapp.jar clojure.main -m myapp.application --server.port=$PORT --server.host=0.0.0.0 It outputs "running on localhost:5000" in Heroku and the app crashes

Spaceman20:04:07

Now when building, I get the error

Step 7/9 : COPY . .
Error processing tar file(exit status 1): write /target/vendo.jar: no space left on device
 ▸    Error: docker build exited with Error: 1
Even after doing
docker system prune --volume