1

I'm trying to build a Docker image that was able to use a Nexus repository, installed in my notebook, when it executes the command RUN mvn package. I added this line to my pom.xml:

<repositories>
    <repository>
        <id>maven-group</id>
        <url>http://localhost:8081/repository/maven-group/</url>
    </repository>
</repositories>

However, localhost should be replaced with the hostname where Nexus is running, but it's on container host (my personal machine). What should I write in the url to point to my repo? My notebook hostname does not resolve from within the container. Or is there any other way to connect to my Nexus repository?

abarazal
  • 369
  • 6
  • 19
  • 2
    You might see if the techniques described in [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach?rq=1) help you; they are a little more focused on `docker run` options, but for example the `host.docker.internal` hostname should work if you're not on a native-Linux host. – David Maze Aug 17 '20 at 11:12
  • David's answer is the correct one. David, you should make this an answer so the OP can award you the Correct Answer checkmark. – John Manko Aug 17 '20 at 20:24

1 Answers1

1

What should I write in the url to point to my repo?

You can place there the Gateway value from the docker inspect command:

$ docker inspect your_docker_container

On the very bottom of the command output in the network section there is: (output for my container, yours can be different)

"Gateway": "172.20.0.1"

So for your example:

<repositories>
    <repository>
        <id>maven-group</id>
        <url>http://172.20.0.1:8081/repository/maven-group/</url>
    </repository>
</repositories>

To be 100% sure you can check if 8081 port is opened in this gateway machine using telnet (run it in from the container):

$ telnet 172.20.0.1 8081
Trying 172.20.0.1...
Connected to 172.20.0.1.
Escape character is '^]'.
jwpol
  • 1,188
  • 10
  • 22