搬运工-构成为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
。
现在我必须手动对文件进行更改才能更改环境,这当然是错误的做法。
我认为应该有办法避免这些手动更改。我怎么做?