Search code examples
dockeramazon-ec2docker-apispotify-docker-client

Docker (Spotify) API - cannot connect to Docker


In my Docker (Spring Boot) application I would like to execute Docker commands. I use the docker-spotify-api (client).

I get different connection errors. I start the application as part of a docker-compose.yml.

This is what I tried so far on an EC2 AWS VPS:

docker = DefaultDockerClient.builder()
  .uri(URI.create("tcp://localhost:2376"))
  .build();
=> TCP protocol not supported. 

docker = DefaultDockerClient.builder()
  .uri(URI.create("tcp://localhost:2375"))
  .build();
=> TCP protocol not supported. 

docker = new DefaultDockerClient("unix:///var/run/docker.sock");
==> No such file

docker = DefaultDockerClient.builder()
          .uri("unix:///var/run/docker.sock")
          .build();
==> No such file

docker = DefaultDockerClient.builder()
            .uri(URI.create("http://localhost:2375")).build();
or
docker = DefaultDockerClient.builder()
            .uri(URI.create("http://localhost:2376")).build();
or 
docker = DefaultDockerClient.builder()
              .uri(URI.create("https://localhost:2376"))
              .build();
==> Connect to localhost:2376 [localhost/127.0.0.1] failed: Connection refused (Connection refused)

Wthat is my environment on EC2 VPS:

$ ls -l /var/run
lrwxrwxrwx 1 root root 6 Nov 14 07:23 /var/run -> ../run

$ groups ec2-user                              
ec2-user : ec2-user adm wheel systemd-journal docker   

$ ls -l /run/docker.sock                       
srw-rw---- 1 root docker 0 Feb 14 17:16 /run/docker.sock

echo $DOCKER_HOST $DOCKER_CERT_PATH
(empty)

Solution

  • This situation is similar to https://github.com/spotify/docker-client/issues/838#issuecomment-318261710.

    You use docker-compose on the host to start up your application; Within the container, the Spring Boot application is using docker-spotify-api.

    What you can try is to mount /var/run/docker.sock:/var/run/docker.sock in you compose file.