我正在尝试通过Dockerfile从使用链接迁移到网络,但我遇到了一些问题。我将首先描绘我的原始设置:
原创 - 链接
Dockerfile:
FROM java:8
VOLUME /tmp
ADD docker_micro_maven-0.0.1-SNAPSHOT.jar app.jar
RUN bash -c 'touch /app.jar'
EXPOSE 8080
ENTRYPOINT ["java","-Dspring.data.mongodb.uri=mongodb://mongodb/micros", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
搬运工-compose.yml:
mongodb:
image: mongo
employee:
image: jdruwe/docker_micro_maven
links:
- mongodb
ports:
- "8080"
新功能 - 网络
Dockerfile:
FROM java:8
VOLUME /tmp
ADD docker_micro_maven-0.0.1-SNAPSHOT.jar app.jar
RUN bash -c 'touch /app.jar'
EXPOSE 8080
ENTRYPOINT ["java","-Dspring.data.mongodb.uri=mongodb://${MONGO_URI_DOCKER}/micros", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
搬运工-compose.yml:
mongodb:
container_name: "db"
image: mongo
employee:
image: jdruwe/docker_micro_maven
environment:
- MONGO_URI_DOCKER=db:27017
ports:
- "8080"
当我在spring boot app(原始情况)中调用我的rest端点时,我总是得到一个响应(一些json数据)。当我现在调用它时,我得到以下错误响应:
{
"timestamp": 1453405937191,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.dao.DataAccessResourceFailureException",
"message": "Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=db:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: db: unknown error}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=db:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: db: unknown error}}]",
"path": "/employee"
}
来自Devoxx的视频我用作参考:https://youtu.be/aSATsLG59Zs?t=53m33s
似乎我一直做错了,但我不确定它是什么,欢迎任何帮助。提前谢谢!
答案 0 :(得分:1)
在docker-compose 1.5.x中,新网络仍然是一项需要使用--x-networking
选项启用的实验性功能。
如果将新的(2.0)文件格式用于docker-compose.yml,新的网络功能将从docker-compose 1.6中移出实验,并自动使用。
阅读docker-compose 1.6-rc1的发行说明以获取更多信息; https://github.com/docker/compose/releases/tag/1.6.0-rc1