# How to run a Gradle Java project in Docker?

**URL:** <https://discuss.gradle.org/t/how-to-run-a-gradle-java-project-in-docker/24838>\
**Category:** Help/Discuss\
**Created:** [November 19, 2017, 3:13am UTC](https://discuss.gradle.org/t/how-to-run-a-gradle-java-project-in-docker/24838 "2017-11-19T03:13:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcelinarcyz](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@marcelinarcyz](https://discuss.gradle.org/u/marcelinarcyz)\
**Post date:** [November 19, 2017, 3:13am UTC](https://discuss.gradle.org/t/how-to-run-a-gradle-java-project-in-docker/24838/1 "2017-11-19T03:13:04Z")

</div>

I have a simple Java server project with a build.gradle script. `gradle run` runs perfectly on my laptop. I create a simple `Dockerfile` for this

```
FROM gradle:4.3-jdk-alpine
ADD . /code
WORKDIR /code
CMD ["gradle", "--stacktrace", "run"]

```

Is there a better way to Dockerize a Gradle project?

I build it with `docker build -t my-server-app .`

Then I run with `docker run --rm my-server-app`

The error I get is:

```
Caused by: org.gradle.api.UncheckedIOException: Failed to create parent directory '/code/.gradle/4.3' when creating directory '/code/.gradle/4.3/fileHashes'
	at org.gradle.util.GFileUtils.mkdirs(GFileUtils.java:271)
	at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:56)

```

Obviously, the docker container should be running as root. Why would I get this error?

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [November 20, 2017, 3:35am UTC](https://discuss.gradle.org/t/how-to-run-a-gradle-java-project-in-docker/24838/2 "2017-11-20T03:35:20Z")

</div>

> [@marcelinarcyz](#):
>
> Obviously, the docker container should be running as root. Why would I get this error?

It’s not, as the base image you’re using, `gradle:4.3-jdk-alpine`, declares that the process should be run as user `gradle`. You can overwrite that in your own `Dockerfile` or use `ADD --chown=gradle . /code` to match what the base image is already expecting.
