Docker Community Forums

Share and learn in the Docker community.

Docker compose can not connect to custom maven repository but docker can connect

hi
i have a spring boot project with maven. i create a maven repository server and my project download repository from that. when i build and run project with docker it can download the dependency from custom server and custom maven settings.xml but when i user docker compose it can not download the repository .
DockerFile :

FROM maven:3-jdk-8-slim
RUN mkdir -p /root/.m2 \
    && mkdir /root/.m2/repository
COPY . /app/
COPY pom.xml .
COPY settings.xml /root/.m2/
COPY settings.xml /usr/share/maven/ref/
WORKDIR /app/
ENTRYPOINT \
    mvn clean install -Dmaven.test.skip -DskipTests -s settings.xml && \
    java -jar \
        -Dspring.profiles.active=${active_profile} \
        -Dserver.port=8082 \
        /app/target/demo-1.0.0.jar

docker-compose.yaml

version: "3"

services:
  demo-ms:
    image: demo:latest
    container_name: demo
    build:
      context: .
      dockerfile: Dockerfile
    tty: true
    ports:
      - "8080:8082"
    expose:
      - "80"
    restart: on-failure
    volumes:
      - /root/.m2:/root/.m2

Please, use the </> button to highlight code blocks. I edited your post to add highlighting.

Do you have any error message?

Observations:

  • Dockerfile
    • settings.xml is copied to /root/.m2
    • settings.xml is copied to /usr/share/maven/ref
    • ENTRYPOINT uses the -s parameter without an absolute path inside the workdir app
  • compose file
    • you do mount the host folder /root/.m2 into the container path /root/.m2, as such the settings.xml that exists inside the image is will become invisible inside the container. A bind mounts a host folder on top of a container folder making its original content (it has from the image) inacessible.

Since you have another copy of settings.xml in /usr/share/maven/ref/, it should work if you replace your -s setting with -s /usr/share/maven/ref/settings.xml

To use the settings.xml from /root/.m2, you will have to replace the bind with a “real” volume - or simply do not bind a host folder into that container folder.

Update: I had a mixup of wording snippets in the post which I removed again.

1 Like

thank you. the error is

Downloading from yasan:"my custom url"/org/springframework/boot/spring-boot-starter-parent/2.3.3.RELEASE/spring-boot-starter-parent-2.3.3.RELEASE.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.example:demo:1.0.0: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.3.3.RELEASE from/to yasan ("my custom url"): transfer failed for "my custom url"/org/springframework/boot/spring-boot-starter-parent/2.3.3.RELEASE/spring-boot-starter-parent-2.3.3.RELEASE.pom and 'parent.relativePath' points at no local POM @ line 5, column 10

but with docker build/run i have no error

i have a settings.xml in root folder. i send this dockerfile and docker-compose setting for show that i try multiple setting but i have same error in docker-compose up --build but not in docker build/run

Your problem is either that the settings.xml is not used, has an incomplete configuration or you suffer from “inconsitent” files. To combat the inconsitant file situation, make sure to add --strict-checksums to your mvn command.

@alirezatali can you please put in your own words what you understood from my previous post? I just want to be sure you actualy put it into consideration when posting your responses.

i think you say that i used this settings.xml file in multiple way and this is a problem. but i say i use these setting Separately like this :

FROM maven:3-jdk-8-slim
COPY . /app/
WORKDIR /app/
ENTRYPOINT \
    mvn clean install -Dmaven.test.skip -DskipTests -s settings.xml  && \
    java -jar \
        -Dspring.profiles.active=${active_profile} \
        -Dserver.port=8082 \
        /app/target/demo-1.0.0.jar

but i has error again. and my question is why this worked with docker but can not work with docker-compose? and i must doing somthing in docker network?

Can you show your working docker command?

first :
docker build --tag=demo:latest -t demo .
then :
docker run -d --name demo -p 8080:8082 demo

Then you may be right with the network if your “parent POM” comes from the internet. If that is possible. I am not very familier with Maven.

Try to check your docker network using curl in the same network you run maven. If your user defined network created by Docker compose is blocked or colliding with another network that can be the issue.

thank you. i found the problem. i declare custom maven repository url in linux hosts file and it worke.