Skip to content

Commit

Permalink
feat: modify docker
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghanzhilian committed Jan 4, 2024
1 parent ab74f60 commit b57b58e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
BASE_URL=http://localhost:3000
MONGODB_URL=mongodb://db:27017/choiceshop
MONGODB_URL=mongodb://localhost:27017/choiceshop
NEXT_PUBLIC_ACCESS_TOKEN_SECRET=h1n0U6LHJtCZuWitwjn3oLd5qCRIgUFtemnjTrpfZLzVZ3ff0f
11 changes: 3 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@ RUN mkdir /app
WORKDIR /app

# 设置环境变量
ENV MONGODB_URL "mongodb://db:27017/choiceshop"
ENV MONGODB_URL "mongodb://172.28.0.1:27017/choiceshop"

# 安装项目依赖
COPY package.json /app
RUN npm install --registry https://registry.npm.taobao.org

COPY . /app
#RUN rm -rf node_modules
#RUN rm -rf package-lock.json
#RUN npm cache clean --force
#RUN npm install
#RUN ping db
RUN npm run build

# 对外暴露端口
EXPOSE 3000

# 启动 Image 时执行命令
CMD npm run start
CMD npm run start
# CMD npm run dev
20 changes: 15 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ services:
target: /data/configdb
ports:
- "27017:27017"
networks:
- stagingnetwork

web:
container_name: web
Expand All @@ -28,12 +30,20 @@ services:
environment:
PORT: 3000
depends_on:
db:
condition: service_completed_successfully
restart: true
required: true
- db
networks:
- stagingnetwork

volumes:
MONGO_DATA:
name: MONGO_DATA
MONGO_CONFIG:
name: MONGO_CONFIG
name: MONGO_CONFIG

networks:
stagingnetwork:
driver: bridge
ipam:
config:
- subnet: 172.28.0.0/16
gateway: 172.28.0.1
1 change: 1 addition & 0 deletions helpers/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ async function connect() {
useNewUrlParser: true,
useUnifiedTopology: true,
socketTimeoutMS: 1000 * 60 * 110,
connectTimeoutMS: 1000 * 60 * 110,
})
console.log('Mongo Connected: ')
console.log('Mongo Connected: process.env.MONGODB_URL', process.env.MONGODB_URL)
Expand Down

0 comments on commit b57b58e

Please sign in to comment.