I want to be able to run two separate apps in two containers - one for each independent app. Then both apps should be able to communicate with the 3rd container which will hold MongoDB.
Folder structure on my local machine
/Users/me/Dev: Dockerfile, docker-compose.yml /Users/me/Dev/App1: with source code and package.json for app1 /Users/me/Dev/App2: with source code and package.json for app2 /Users/me/Dev/data/db: I wanna keep datafile for Mongodockerfile - but honestly it does not look right too me to repeat twice for both apps. (Its a first time I am using docker so am not yet familiar with how to best prepare the Dockerfile for my scenario)
FROM node:8.9.1 WORKDIR ./app1/ COPY ./package.json ./app1/ RUN npm install CMD npm start COPY ./app1/ ./app1/ EXPOSE 8081 # FROM node:8.9.1 WORKDIR ./app2/ COPY ./package.json ./app2/ RUN npm install CMD npm start COPY ./app2/ ./app2/ EXPOSE 8082docker-compose.yml
version: '2' services: app1: build: . volumes: - .:/app1 ports: - "8082:8082" links: - mongo depends_on: - mongo # app2: # build: . # volumes: # - .:./app2 # ports: # - "8081:8081" # links: # - mongo # depends_on: # - mongo mongo: image: mongo:3.4.10 volumes: - './dev/data/db:/data/db' ports: - "27017:27017"
Few issues: On docker-compose build for example I got - ERROR: Service 'app1' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder287108072/package.json: no such file or directory
Even if I tried multiple ways of providing the path in Dockerfile and d-compose I still am not convinced this is gonna work.
So I need some guidance on how to prepare Dockerfile and docker compose in my main DEV folder (as described above) so that docker will start up 3 containers (app1, app2, mongo) all on the same docker network to communicate with each other.