在我的Docker(Spring Boot)应用程序中,我想执行Docker命令。我使用docker-spotify-api(客户端)。
我得到不同的连接错误。我作为docker-compose.yml的一部分启动应用程序。
到目前为止,这是我在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)
那是我在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)
最佳答案
这种情况类似于https://github.com/spotify/docker-client/issues/838#issuecomment-318261710。
您在主机上使用docker-compose启动应用程序;在容器内,Spring Boot应用程序正在使用docker-spotify-api。
您可以尝试在组合文件中挂载/var/run/docker.sock:/var/run/docker.sock。
关于docker - Docker(Spotify)API-无法连接到Docker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55891223/