Cider: [Discuss] How to let CIDER make use of Clojure docker image?

Created on 25 Dec 2018  路  8Comments  路  Source: clojure-emacs/cider

This is a discuss, but in order to keep records down, and might help other people. So I record it here. I know there is a channel #cider/#emacs on Slack. I will post this link over there.

I want to use different version and environment of Clojure. There is an official Clojure Docker image. https://hub.docker.com/_/clojure

I'm thinking how to use Clojure image's binary and REPL in Emacs, and CIDER.

There are some ways can access Docker image as I know:

  • running container which started Clojure REPL, user can attach it with Emacs package docker.el.
  • use Emacs package docker-tramp.el and docker.el to access clojure container binary commands like clojure, clj etc. So that Emacs use them as executable command path. Like CIDER has customize option cider-clojure-cli-command. I tried following, but failed.
(add-to-list 'exec-path "/docker:clojure:/usr/local/bin/")
(setq cider-clojure-cli-command "/docker:clojure:/usr/local/bin/clojure")
  • run the clojure image to expose the ip:port to host system. So that Emacs can access the Docker container just like host system local. I don't know how to do that yet.

Anyone have suggestion and solution? Welcome to add. (This might could add to Wiki, when the discussion is almost) Thanks for viewing.

Most helpful comment

@darkleaf I see. Thanks.

@zilti switch Java version, Clojure version is simpler on Docker? and It's cleaner. Easy to package image then share, simpler to reproduce environment issue. I admit Leiningen and Boot (I have not use it myself) is great. Still thanks for your advice.

All 8 comments

I found CIDER has an variable to keep connection records. Could be used in upper mentioned case.

Like this:

(setq cider-known-endpoints
  '(("host-a" "10.10.10.1" "7888")
    ("host-b" "7888")))
  • use CIDER remote host SSH support to SSH into Docker container
  • Use CIDER transparent TRAMP support to use Emacs package docker-tramp.el to open files on container, then cider-jack-in-*, CIDER could transparently handling this.

I use docker-compose and volumes:

# docker-compose.yml
version: '3'

volumes:
  m2:
  gitlibs:

services:
  app:
    image: clojure:tools-deps-alpine
    working_dir: "${PWD}"
    command: "true"
    ports:
      - "4444:4444" # nrepl
      - "4445:4445" # http
    environment:
      - "CLJ_CONFIG=${PWD}/.docker-clojure"
      - DATABASE_URL=postgres://postgres:password@db:5432/postgres
      - TEST_DATABASE_URL=postgres://postgres:password@test-db:5432/postgres
      - PORT=4446
    volumes:
      - ".:${PWD}:cached" # cached - MacOS option
      - m2:/root/.m2
      - gitlibs:/root/.gitlibs
    links:
      - db
      - test-db
  db: &db
    image: postgres:10.4-alpine
    environment:
      - POSTGRES_PASSWORD=password
  test-db:
    <<: *db
;; .docker-clojure/deps.edn
{:aliases {:cider {:extra-deps {darkleaf/cider-tools-desp
                                {:git/url "https://github.com/darkleaf/cider-tools-deps.git"
                                 :sha     "1025b510db24b36ab741bc5599e36806eec904ec"}}
                   :main-opts  ["-m" "darkleaf.cider-tools-deps"
                                "port" "4444" "host" "0.0.0.0"]}
           :repl  {:extra-deps {darkleaf/repl-tools-deps
                                {:git/url "https://github.com/darkleaf/repl-tools-deps.git"
                                 :sha     "04e128ca67785e4eb7ccaecfdaffa3054442358c"}}
                   :main-opts  ["-m" "darkleaf.repl-tools-deps"]}

           :run-tests {:extra-deps {com.cognitect/test-runner
                                    {:git/url "https://github.com/cognitect-labs/test-runner.git"
                                     :sha     "028a6d41ac9ac5d5c405dfc38e4da6b4cc1255d5"}}
                       :main-opts  ["-m" "cognitect.test-runner"]}

           :coverage {:extra-deps {cloverage {:mvn/version "1.0.13"}}
                      :main-opts  ["-m" "cloverage.coverage" "-p" "src"  "-s" "test"]}}}

I run docker-compose run --rm --service-port app bash and than clojure -Acider.
In emacs I press C-c M-c and connect to localhost:4444.

Dependencies are installed into volumes. So Emacs can't have access to them.

Dependencies are installed into volumes. So Emacs can't have access to them.

I'm confused on this. Dependencies are installed into volumes, but Emacs CIDER connect to container started clojure -Acider alias. So if clojure -Acider should be able to access all dependencies in container. Add project dependencies into a container deps.edn file?

Can Docker access host system's .m2/ dependencies? So that Docker will be a bridge between Emacs CIDER and host system dependencies.

We have Maven and tools like Boot and Leiningen, why on earth would Docker be even necessary here? Just because it's trendy?

@stardiviner

I'm confused on this.

REPL is started inside a docker container. This process have access to container file system
with container related paths. Lock at volumes section:

    volumes:
      - ".:${PWD}:cached" # cached - MacOS option
      - m2:/root/.m2
      - gitlibs:/root/.gitlibs

$PWD is /User/darkleaf/projects/project for example. So the project sources are
available in the same path inside container .
It's make sense. REPL can send to Emacs some path and that path is container related.
Emacs can't get a file on host file system if paths are inconsistent.
So I use ${PWD}.

Later I used to mount .m2 and .gitlibs from host file system.
I use Docker for Mac and it's host volumes are slow. So I switched to container volumes.

@darkleaf I see. Thanks.

@zilti switch Java version, Clojure version is simpler on Docker? and It's cleaner. Easy to package image then share, simpler to reproduce environment issue. I admit Leiningen and Boot (I have not use it myself) is great. Still thanks for your advice.

Seems you've sorted this out, so I'll close this ticket.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

harold picture harold  路  7Comments

mwfogleman picture mwfogleman  路  3Comments

lilactown picture lilactown  路  5Comments

achikin picture achikin  路  7Comments

oskarkv picture oskarkv  路  5Comments