在Docker裡面使用nodemon的方法

下午3:22:00


這是我的Docker檔案的寫法
# 抓Node官方image
FROM node:10

# 建立資料夾給app使用
RUN mkdir -p /usr/src/app

# 轉換到app資料夾
WORKDIR /usr/src/app

# 安裝nodemon
RUN npm install -g nodemon

# 要執行的Port
EXPOSE 4000

# 執行
RUN ["chmod", "+x", "/usr/src/app"]

Docker-compose的寫法

### GraphQL ###
graphql:
build:
context: ./graphql
working_dir: /usr/src/app
# environment:
# - NODE_ENV=production
volumes:
- /18T/dev/sites/graphql-server:/usr/src/app
ports:
- "4000:4000"
command: "nodemon index.js"
networks:
- frontend
- backend
depends_on:
- nginx
跑了之後畫面因該會像是這樣

graphql_1              | [nodemon] 1.18.10
graphql_1              | [nodemon] to restart at any time, enter `rs`
graphql_1              | [nodemon] watching: *.*
graphql_1              | [nodemon] starting `node index.js`
graphql_1              | ? Server ready at http://localhost:4000/
graphql_1              |
graphql_1              | > graphql-server@1.0.0 dev /usr/src/app
graphql_1              | > nodemon index.js
graphql_1              |
graphql_1              | [nodemon] 1.18.10
graphql_1              | [nodemon] to restart at any time, enter `rs`
graphql_1              | [nodemon] watching: *.*
graphql_1              | [nodemon] starting `node index.js`
graphql_1              | ? Server ready at http://localhost:4000/

技術提供:Blogger.