How to deploy inside an existing container?
I'm pretty new to IntelliJ (and Docker) so please excuse me if this question is inherently daft - I feel like I must be missing something.
I'm developing a Cloud Run service (in node.js) which has to be built as a Docker container. I can deploy that locally, which is a bit faster than uploading every incremental build to Google, but it still seems bizarre that I have to spend a minute and a half rebuilding the entire container every time I want to change a line of code.
Outside a container, I could just save an edited source file and restart node (when a restart is even needed; much of my app is client-side code which node just serves as static files). I feel like once the Docker container exists, IDEA should similarly be able to deploy updated source files into it (and restart node if needed) rather than rebuilding the whole thing.
Is there a way to do that? Or achieve an equivalent result - something using the "bind mounts" mentioned here, maybe? https://www.jetbrains.com/help/idea/dockerfile-run-configuration.html
Thanks in advance!
Please sign in to leave a comment.
Hello Transhumanist.
Yes, you can use the bind mount feature, which allows you to mount the directory on your local PC to the Docker container. All changes made on the local PC should be reflected inside the container and vice versa.
Also, you can try using the
docker cpcommand; more details regarding it are provided here.Thank you Olga.
I tried exploring this but I'm still a bit stumped. The IDEA run configuration I'm using for local deployment (Cloud Code:Cloud Run:Run Locally) doesn't seem to provide any field for supplying additional arguments to docker run. Docker Target and Docker Environment are there, but the other options that appear in the Docker:Dockerfile run configuration, including bind mounts, aren't available.
I tried creating a Docker:Dockerfile configuration with a bind mount specified, then copied the relevant <option> from the saved .xml copy of that to a Cloud Run configuration, but that had no visible effects (it was a bit of a long shot, given I have no real idea how the xml is parsed).
I'm a bit puzzled also that when I step in to the Docker container via a terminal, the app code isn't accessible in the file system location mentioned (as WORKDIR) in the Dockerfile (which is /usr/src/app) - that folder doesn't even exist; the files do exist in the container, but only in Docker's overlay2 folders. This probably reflects my crude grasp of how Docker works, but it seems like it might also be interfering with setting a bind mount to that location.
The run configuration starts by launching Minikube, so with a bit more reading I'm starting to wonder whether what I actually need is not a Docker bind mount but a skaffold file sync directive. It looks like that would go in skaffold.yaml, but there isn't one; from the build output, Cloud Code generates a temporary file for the skaffold config.
It would be incredibly useful to know what a given run configuration does under the hood - maybe then I could create a custom one that recapitulates what the Cloud Run:Run Locally config does, but with the additional step of adding a bind mount and/or file sync rule...
I'm going to keep exploring this, but any further insights anyone has - or suggestions of a better place to post this query! - would be appreciated :-)
Transhumanist, since you use Cloud Run, not the ordinary Docker Run configuration, I'd recommend you to ask this question on StackOverflow, as it is recommended here. We do not develop and support this plugin, so I'm afraid this problem is out of my competence.