0

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.

pradip kundu
  • 51
  • 2
  • 5
  • 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

2 Answers2

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
  • 460
  • 3
  • 12
0

Just add directive command see example. my base image is alpine. Now i am starting my image with composer and installing java. This working for me

command: apk add --update openjdk11

---

networks:
  imaspc:
    external: true

services:
  hello_world:
    image: test1:latest
    container_name: test1
    hostname: test1
    tty: true
    env_file:
      - postgr.env
    command: apk add --update openjdk11
    networks:
      - imaspc
    labels:
        - "dbengine=postgres"
        - "dbversion=14"
user2308728
  • 91
  • 1
  • 2