Reputation: 607
I am using Docker Compose for multi-container application I have two docker-files one for tomcat and one for ant first tomcat docker file build successfully and when the ant docker-file build my application it required tomcat/lib folder and tomcat/webapps which is present in another container so how i get the tomcat folder present in tomcat container in ant container so that my application will build successfully
now i am getting an error
tomcat/lib not found...
my docker-compose.yml :
version: '3'
services:
ant:
build:
context: "."
dockerfile: dockerfile_ant
container_name: ant-container
volumes:
- ant:/usr/local/tomcat:ro
links:
- tomcat
ports:
- "8080:8080"
tomcat:
build:
context: "."
dockerfile: dockerfile_tomcat
container_name: tomcat-container
volumes:
- ant:/usr/local/tomcat:rw
expose:
- 80
volumes:
ant:
my dockerfile_ant:
FROM openjdk:6
MAINTAINER shri
ENV ANT_HOME /usr/local/ant
ENV PATH ${PATH}:/usr/local/ant/bin
ENV ANT_OPTS=-Dfile.encoding=cp1252
ADD apache-ant-1.7.0 /usr/local/ant
ADD TemplateUI /usr/local/TemplateUI
WORKDIR /usr/local/TemplateUI
ENV JAVA_TOOL_OPTIONS=-Dfile.encoding=cp1252
RUN ant
My dockerfile_tomcat:
FROM tomcat:6
ENV CATALINA_HOME /usr/local/tomcat
ENV PATH $CATALINA_HOME/bin:$PATH
RUN mkdir -p "$CATALINA_HOME"
VOLUME ant
WORKDIR /usr/local/tomcat
EXPOSE 8009
Please guide us in which way you can run your multi-container application using docker compose .
Thanks shriyash
Upvotes: 3
Views: 4895
Reputation: 607
this is the docker-compose.yml:-
version: '3.2'
services:
ant:
build:
context: "."
dockerfile: dockerfile_ant
container_name: ant-container
links:
- tomcat
volumes:
- ant:/usr/local/tomcat:rw
ports:
- "8080:8080"
tomcat:
build:
context: "."
dockerfile: dockerfile_tomcat
container_name: tomcat-container
restart: always
volumes:
- ant:/usr/local/tomcat:rw
expose:
- 80
volumes:
ant: {}
and no need to specify volume in ant-dockerfile and tomcat-dockerfile
Upvotes: 3
Reputation: 14903
You can define named volumes in compose file & share it across multiple containers by adding those volume names in volume
section of compose file for each container.
Ref - https://docs.docker.com/compose/compose-file/#volumes
Example (logs
volume is shared across multiple containers )-
version: '3.2'
services:
lr:
build:
context: ./docker-build
dockerfile: Dockerfile.lr
restart: always
volumes:
- logs:/rest/logs/
redis:
image: redis:alpine
volumes:
- data:/data
- logs:/rest/logs/
volumes:
logs:
data:
Alternatively, you can also you host bind/mount volumes as well but try not to use them(host-bind-volumes) as much as possible.
Upvotes: -1