我是码头新手。我想用我的web应用程序创建一个图像。我需要一些应用服务器,例如wlp,然后我需要一些数据库,例如postgres。
wlp有Docker映像,postgres有Docker映像。
因此,我创建了以下简单的Dockerfile。
FROM websphere-liberty:javaee7
FROM postgres:latest现在,也许这是个蹩脚的,但当我建立这个形象
docker build -t wlp-db .运行容器
docker run -it --name wlp-db-test wlp-db检查一下
docker exec -it wlp-db-test /bin/bash只有postgres在运行,wlp甚至不在那里。目录/opt为空。
我遗漏了什么?
发布于 2018-01-16 14:59:17
你需要使用坞-合成文件。这使您可以绑定两个运行两个不同映像的不同容器。一个保存您的服务器,另一个保存数据库服务。
下面是使用mongodb容器的nodejs服务器容器的示例
首先,我编写了文件来配置主容器
FROM node:latest
RUN mkdir /src
RUN npm install nodemon -g
WORKDIR /src
ADD app/package.json package.json
RUN npm install
EXPOSE 3000
CMD npm start然后,我创建了文件来配置这两个容器,并将它们链接到。
version: '3' #docker-compose version
services: #Services are your different containers
node_server: #First Container, containing nodejs serveer
build: . #Saying that all of my source files are at the root path
volumes: #volume are for hot reload for exemple
- "./app:/src/app"
ports: #binding the host port with the machine
- "3030:3000"
links: #Linking the first service with the named mongo service (see below)
- "mongo:mongo"
mongo: #declaration of the mongodb container
image: mongo #using mongo image
ports: #port binding for mongodb is required
- "27017:27017"希望这能帮上忙。
发布于 2018-01-16 14:55:26
每个服务都应该有自己的映像/dockerfile。启动多个容器,并通过网络将它们连接起来,以便能够进行通信。
如果您希望在一个文件中组合多个容器,请查看docker-compose,它就是为此创建的!
发布于 2018-01-16 14:58:36
您不能在一个文件中多次运行,并且希望两个进程都运行
这是从图像中创建每个层,但是进程只有一个入口点,即Postgres,因为它是第二个
这种模式通常只有当您有一些“安装”停靠映像,然后在上面有一个“运行时”映像时才能完成。
https://docs.docker.com/engine/userguide/eng-image/multistage-build/#use-multi-stage-builds
另外,你想要做的是不太坚持“微服务”。将数据库与应用程序分开运行。Docker Compose可以帮助你,而且几乎所有Docker网站上的例子都使用Postgres和一些web应用程序。
另外,您正在启动一个空的数据库和服务器。例如,您需要至少复制一个WAR来运行您的服务器代码。
https://stackoverflow.com/questions/48283990
复制相似问题