I'm trying to create a simple Dockerfile to start using only Docker for local development. Currently the image builds and lein figwheel
runs successfully, but since I'm using ADD . /app
, when I try to edit the files from the outside with my editor, I believe the files inside the container don't change since they were added during build phase and aren't linked to the files outside?
This is what I have so far:
FROM clojure:lein-alpine
WORKDIR /app
ADD . /app
RUN lein deps
EXPOSE 3449
CMD ["lein", "figwheel"]
I have another problem which is that I'm using Fedora with SELinux being enforced. I've read a bit about using z and Z to mount volumes, but I still can't get it right.
Ideas on how to improve this? Thank you!Instead of copying the files, you probably want to mount a volume, https://docs.docker.com/storage/volumes/ this probably works better/only when using docker compose instead of a dockerfile.
@anantpaatra here’s an example docker-compose.yml
you can extend to your needs. Put this file into your project root.
version: '2'
services:
base:
image: clojure:lein
working_dir: /usr/src/app
volumes:
- '.:/usr/src/app'
- 'mvn_cache:/root/.m2'
lein:
extends:
service: base
entrypoint: lein
figwheel:
extends:
service: lein
command: figwheel
tty: true
ports:
- '3449:3449'
shell:
extends:
service: base
command: bash
volumes:
mvn_cache: {}
- '.:/usr/src/app'
(under base
) will mount your project dir .
into the container(s) path /usr/src/app
. This way both your host machine and container(s) see the same files and any changes will persist on your host machine after container has terminated. Additinally there’s a separate volume for Maven cache, which you want to share between your containers (otherwise maven downloads dependencies each time you execute lein commands). Volume(s) defined at the bottom will ‘survive’ until they’re explicitly deleted.
Usage:
docker-compose run lein <args>
executes any lein tasks. Example: docker-compose run lein clean
docker-compose up figwheel
fires up figwheel which will be accessible from host on port 3449. (ctrl-c will quit). You need to use up
instead of run
because run doesn’t allocate port mappings and therefore you’d never be able to access index.html from your host machines browser.
docker-compose run shell
starts a bash session in container, for exploring and fun.
docker-compose down
removes all containers.
docker-compose down -v
shuts down all containers and removes mvn_cache volume.Than you @valtteri, really. That saved me weeks.
I'm really not a DevOps guy. Even after so many Docker tutorials I had no idea such a setup was possible.
Thank you as well @gklijs!
No problem! I’ve been fiddling with Docker quite a bit during the last couple of years. At work we share our dev/ci envs like this. Let me know if you have further questions. Finding the correct spells might be tedious sometimes. 🙂
Thank you 🙂