无法使用docker-compose.yml在docker之间建立连接
我是新来的码头世界,所以事先道歉,如果我的问题不清楚。所以我要做的是有两个码头,一个是休息服务,另一个是休息客户端。我正在尝试建立两者之间的网络连接
docker rest服务路径/Users/gsha/learning/producer我的rest服务详细信息
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ProducerApplication {
public static void main(String[] args) {
SpringApplication.run(ProducerApplication.class, args);
}
}
server.port=8085
server.servlet.context-path=/producer-service
Path of this Dockerfile /Users/gsha/learning/producer
Rest Client Info路径/用户/gsha/学习/消费者
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ConsumerApplication {
public static void main(String[] args) {
SpringApplication.run(ConsumerApplication.class, args);
}
}
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class SimpleRestConsumer {
@RequestMapping("/")
public String getHello(){
RestTemplate restTemplate = new RestTemplate();
String val = restTemplate.getForObject("http://localhost:8085/producer-service", String.class);
return val;
}
}
server.port=8086
server.servlet.context-path=/consumer-service
address.service.base-path=http://localhost:8085/producer-service
yaml文件路径:/Users/gsha/learning/docker- composer .yml(我很困惑,如果这是放置yaml文件的正确路径)(有人能帮助我如何写这个yaml文件…有些困惑)
version: "3"
services:
producer-service:
build:
context: ../producer-service
dockerfile: ./Dockerfile
ports:
- 8085:8085
consumer-service:
build:
context: ../consumer-service
dockerfile: ./Dockerfile
ports:
- 8086:8086
depends_on:
- producer-service
Getting this error when doing the deployment
docker-compose up --build
[+] Building 0.0s (0/0)
unable to prepare context: path "../producer-service" not found
我假设您的目录是这样的
├── learning
│ ├── producer
│ | └── Dockerfile # Dockerfile for Producer
│ ├── consumer
│ | └── Dockerfile # Consumer Dockerfile
│ └── docker-compose.yml
└── …
似乎你的构建上下文路径不正确。试试这个
version: "3"
services:
producer-service:
build:
context: .
dockerfile: ./producer/Dockerfile
ports:
- 8085:8085
consumer-service:
build:
context: .
dockerfile: ./consumer/Dockerfile
ports:
- 8086:8086
depends_on:
- producer-service
为生产者和消费者服务添加正确的Dockerfile路径。根据./producer/Dockerfile
和./consumer/Dockerfile
中存在Dockerfile
的假设,我添加了一个示例路径