With the Dockerfile Run Configuration, is it possible to specify a volume mount relative to project root?

Answered

I'm attempting to create VCS shareable run configurations using the Dockerfile run configuration, in some of my Java projects.

 

As part of the Docker run config, I would like to specify a volume mount, which will mount a log file path in the container to a local folder which is underneath my project's root.


I've tried just about everything and my Google-fu is failing me. Is it possible in the Bind Mounts: section of the config, to somehow specify a host path which is relative to the project root, but the Docker daemon will recognize? Starting the host path with "./" or no slash at all doesn't seem to work. Only absolute paths seem to work, and I cannot guarantee that different developers will have their project root in the same place on their local filesystem. So I do not want to share an absolute local path.

0
4 comments

When the XML configuration is saved on disk, do you see the absolute path there or do you see the project path part automatically replaced with the $PROJECT_DIR$?

0
Avatar
Permanently deleted user

No, it is absolute. Here's the XML snippet (lightly redacted) for the run config. Only place I see the variable is in the BeforeRunTask where I build my project before the dockerfile copies the .war into the container.

<configuration name="Run in Docker" type="docker-deploy" factoryName="dockerfile" server-name="Local Docker">
<deployment type="dockerfile">
<settings>
<option name="buildCliOptions" value="" />
<option name="command" value="/entrypoint.sh --debug *:8787 " />
<option name="containerName" value="my-project-name" />
<option name="entrypoint" value="" />
<option name="imageTag" value="my-project-name" />
<option name="portBindings">
<list>
<DockerPortBindingImpl>
<option name="containerPort" value="8080" />
<option name="hostPort" value="8080" />
</DockerPortBindingImpl>
<DockerPortBindingImpl>
<option name="containerPort" value="8787" />
<option name="hostPort" value="8787" />
</DockerPortBindingImpl>
</list>
</option>
<option name="commandLineOptions" value="--env-file ./config/vars/env-file.env" />
<option name="sourceFilePath" value="local.Dockerfile" />
<option name="volumeBindings">
<list>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/opt/jboss/wildfly/standalone/log" />
<option name="hostPath" value="C:\repos\my-project-dir\logs" />
</DockerVolumeBindingImpl>
</list>
</option>
</settings>
</deployment>
<method v="2">
<option name="Gradle.BeforeRunTask" enabled="true" tasks="build" externalProjectPath="$PROJECT_DIR$" vmOptions="" scriptParameters="" />
</method>
</configuration>

I've also stumbled upon $PROJECT_DIR$ on the youtrack ticket for adding params like this to run configs. And through the GUI at least, I've attempted to set the value for hostPath to contain that value (ie. $PROJECT_DIR$\logs instead of C:\repos\my-project-dir\logs). That results in the following error when the image is being built from the dockerfile:

Failed to deploy 'my-project-name Dockerfile: local.Dockerfile': $PROJECT_DIR$\logs:/opt/jboss/wildfly/standalone/log%!(EXTRA string=is not a valid Windows path)

0
Avatar
Permanently deleted user

Thanks. Voted. Also, the comments there helped. I think I was getting an absolute path because I was using backslashes. When I hand-edited the XML as follows

<DockerVolumeBindingImpl>
<option name="containerPath" value="/opt/jboss/wildfly/standalone/log" />
<option name="hostPath" value="$PROJECT_DIR$/logs" />
</DockerVolumeBindingImpl>

things work, and I notice that in the GUI, the backslashes become forward slashes. So the ticket is correct - it works, you just have to handroll the XML. Having this work right in the GUI would be optimal. I know other devs on my team will eventually break the hand-edited XML.

Also, is the term for variables like $PROJECT_DIR$ "macro variables"? Just so I know what to search for in the future.

0

Please sign in to leave a comment.