amazon-web-servicesdockerubuntuaws-cloudformationarangodb

ArangoDB Fail to Start on AWS EC2 with Docker and Java


I have a setup in which a Java program is used to start the ArangoDB. Following code will start the ArangoDB.

  ProcessBuilder processBuilder = new ProcessBuilder(arangodExecFile);
  processBuilder.environment().put("hostaddress", host);          
  arangodbProcess = processBuilder.start();

I have also tried using arangodbProcess = Runtime.getRuntime().exec(arangodExecFile, env_hostaddress); The program is running inside a Docker container that uses Ubuntu as a base image. The implementation is working fine, and ArangoDB starts without any issues.

When I deploy the same Docker image on an AWS EC2 instance, ArangoDB fails to start with the following error:

2023-10-25T10:26:08Z [50] ERROR [874fa] {communication} unable to bind to endpoint 'http+tcp://host_ip:8529': Address not available
2023-10-25T10:26:08Z [50] FATAL [c81f6] {general} failed to bind to endpoint 'http+tcp://host_ip:8529'. Please check whether another instance is already running using this endpoint and review your endpoints configuration.

I do not have an ENDPOINTS file. The server.endpoint is properly configured to start the ArangoDB on the AWS instance, using the AWS instance's IP address. I am using the AWS instance IP to bind the server endpoint so that I can access it from a different machine. Making a call to ArangoDB endpoint is done from a different AWS instance to get ArangoDB driver and it should not affect the starting of ArangoDB, it can cause an issue when I try to get the ArangoDB object of the ArangoDB process which is running.


Solution

  • I'm assuming that by "deploy the same Docker image on an AWS EC2 instance" you mean that you have set up Docker on your EC2 instance, and it serves a Docker host.

    Applications running inside a Docker container, by default, don't have access to your host's network. It means that your ArangoDB instance won't see any of your EC2 instance's IP addresses. What it will see is the Docker virtual network with its own IP address.

    Docker has the ability to forward packets between the host network and the container's network. To do that, you need to expose the ports that you want forwarded. You can do that by publishing your containers ports to the host by using docker run --publish 8529:8529 or similar.

    Inside your container, you should bind your listening socket to the internal network interface. You can do this by getting your container's hostname from within the container, and, optionally, resolving its IP address (if ArangoDB requires binding by IP). When starting containers, Docker rewrites their /etc/hosts so that the container's hostname resolves to its internal address. You won't need to pass the host address from the outside anymore.

    Alternatively, you can run your Docker container so that it shares the host's network (by using docker run --network=host), but it's less secure and harder to configure (this way, you do need to know the host address to bind your listening socket to).