简体   繁体   中英

docker-compose start two node apps

I have structure like this:

├── api
│   ├── server.js
│   ├── Dockerfile
├── docker-compose.yml
└── web
    ├── client
    ├── Dockerfile
    ├── node_modules
    ├── package.json
    └── server

2 Dockerfiles and one docker compose file in root,how can I run both apps with docker compose?

I tried like this:

compose file:

services:
  web:
    build: ./web .
    volumes:
        - .:/app
    ports:
        - "4200:4200"
    restart: always
    command: npm start
   server:
    build ./api .
    volumes:
        - .:/app
    ports:
        - "3100:3100"
    restart: always
    environment:
        - NODE_ENV=production
    command: npm start

Api docker file example:

FROM node:6.9.4

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

RUN npm install nodemon -g

# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install

# Bundle app source
COPY . /usr/src/app

EXPOSE 3100

But get error for this part: build: ./web .

Any solution for this?

You've got an extra dot on your build line. The period is normally the current directory to indicate the context, but you just need to change that to the directory, not add an extra section. There's also a spacing issue on your server line, yaml files are whitespace sensitive. Lastly, make sure to include the version line:

version: '2'
services:
  web:
    build: ./web
    volumes:
        - .:/app
    ports:
        - "4200:4200"
    restart: always
    command: npm start
  server:
    build ./api
    volumes:
        - .:/app
    ports:
        - "3100:3100"
    restart: always
    environment:
        - NODE_ENV=production
    command: npm start

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM