搬運工-構成爲PROD:Dockerfile和搬運工-compose.yaml針對不同的環境
version: '2'
services:
db:
image: mongo:3
ports:
- "27017:27017"
api-server:
build: .
ports:
- "443:443"
links:
- db
volumes:
- /www/node_modules
Dockerfile爲PROD:
FROM alpine:3.4
LABEL authors="John Doe"
RUN apk add --update nodejs bash git
COPY package.json /www/package.json
RUN cd /www; apk --no-cache add --virtual builds-deps build-base python && npm install && npm rebuild bcrypt --build-from-source && apk del builds-deps
COPY . /www
WORKDIR /www
ENV PORT 8080
EXPOSE 8080
CMD ["npm", "start"]
搬運工-構成用於開發:
version: '2'
services:
db:
image: mongo:3
ports:
- "27017:27017"
api-server:
build: .
ports:
- "8080:8080"
links:
- db
volumes:
- .:/www
- /www/node_modules
dev的Dockerfile
FROM alpine:3.4
LABEL authors="John Doe"
RUN apk add --update nodejs bash git
COPY package.json /www/package.json
RUN cd /www; apk --no-cache add --virtual builds-deps build-base python && npm install && npm rebuild bcrypt --build-from-source && apk del builds-deps
WORKDIR /www
ENV PORT 8080
EXPOSE 8080
CMD ["npm", "run", "dev"]
我正在運行它docker-compose up
。
現在我必須手動對文件進行更改才能更改環境,這當然是錯誤的做法。
我認爲應該有辦法避免這些手動更改。我怎麼做?