我有这个撰写文件,我希望有一个应用程序有两个运行MySql和Mongodb的数据库。所有这些都装入容器并最终连接起来。
version : '2'
services:
springappserver:
build:
context: .
dockerfile: springapp.dockerfile
ports:
- "8081:8081"
networks:
- net-spring-db1
- net-spring-db2
volumes:
- .:/vol/development
depends_on:
- mysqldbserver
- mongodbserver
mongodbserver:
build:
context: .
dockerfile: mongodb.dockerfile
ports:
- "27017:27017"
networks:
- net-spring-db2
volumes:
- ./data/db:/data/db
container_name: mongodbserver
mysqldbserver:
build:
context: .
dockerfile: mysqldb.dockerfile
ports:
- "3306:3306"
networks:
- net-spring-db1
environment:
MYSQL_DATABASE: testdb1
MYSQL_USER: myuser
MYSQL_PASSWORD: mypassword
MYSQL_ROOT_PASSWORD: myrootpassword
MYSQL_DATABASE: testdb2
MYSQL_USER: myuser
MYSQL_PASSWORD: mypassword
MYSQL_ROOT_PASSWORD: myrootpassword
container_name: mysqldbserver
networks:
net-spring-db1:
driver: bridge
net-spring-db2:
driver: bridge
我还有3个dockerfiles
第一个是应用程序:
FROM java:8
# maintainer
MAINTAINER Bill
# update packages and install maven
RUN \
export DEBIAN_FRONTEND=noninteractive && \
sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list && \
apt-get update && \
apt-get -y upgrade && \
apt-get install -y vim wget curl maven
# attach volumes
VOLUME /vol/development
# create working directory
RUN mkdir -p /vol/development
WORKDIR /vol/development
# maven exec
CMD ["mvn", "clean", "package", "exec:java"]
第二个用于MySql服务器:
FROM mysql/mysql-server
MAINTAINER Bill
# Copy the database initialize script:
# Contents of /docker-entrypoint-initdb.d are run on mysqld startup
ADD mysql/ /docker-entrypoint-initdb.d/
第三个是Mngodb:
FROM mongo:3.4
MAINTAINER Bill
# assume you are in mongo bin directory
RUN mongod
1)我的问题是最后一个挂起等待,所以我怀疑它需要一些参数才能完美运行。
2)我的撰写yml文件是否正确或需要调整?
答案 0 :(得分:0)
您的mongo Dockerfile不正确。在构建图像时,您不应该运行mongod。 RUN命令将在映像构建时执行。 mongod命令用于在容器启动后启动mongo进程。
将mongodb Dockerfile更改为以下内容:
FROM mongo:3.4
MAINTAINER Bill