-1

I am building an node mongo project. I am using docker compose for the project. here is my dockerFile

FROM node:carbon
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]

Here is docker-compose.yml

version: "2"
services:
  app:
    container_name: app
    restart: always
    build: .
    ports:
      - "3000:3000"
    links:
      - mongo
  mongo:
    container_name: mongo
    image: mongo
    volumes:
      - ./data:/data/db
    ports:
      - "27017:27017"

Here I also want to install java using docker-compose. As I will need java for elastic search and for other purposes. So can any one help about how to install java using docker-compose in this project.

  • What have you researched so far? – Thorbjørn Ravn Andersen Mar 19 '20 at 19:37
  • Besides @ThorbjørnRavnAndersen 's comment, I would urge you to consider using two different docker containers. One for your node.js application and one for your Elastic Search storage. It looks like you're doing that with your Mongo container... Btw, there should be Elastic Search containers already out there to use, but if you want to install it yourself, use one of the OpenJDK containers and then install Elastic Search on that container. – hooknc Mar 19 '20 at 19:40
  • I would look at this https://stackoverflow.com/questions/49800652/run-java-in-docker-compose. – user254694 Mar 20 '20 at 08:28

1 Answers1

2

Docker-compose is a tool used to launch multiple containers from a single .yaml file.

Add this line to your Dockerfile to install Java:

RUN apt-get update && \
apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean;
D. Richard
  • 384
  • 2
  • 11