Skip to content

Commit

Permalink
Docker周りのファイルを修正, Docker Imageの軽量化と不要なオプションを削除
Browse files Browse the repository at this point in the history
  • Loading branch information
AobaIwaki123 committed Apr 1, 2024
1 parent a33dd9a commit cd082d4
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 15 deletions.
2 changes: 1 addition & 1 deletion api/api.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10
FROM python:3.10-slim-bookworm

WORKDIR /api

Expand Down
10 changes: 3 additions & 7 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ services:
container_name: "view"
build:
context: ./view
dockerfile: view.Dockerfile
volumes:
- ./view:/view
- ./view/node_modules:/view/node_modules
command: sh -c "yarn start"
dockerfile: prod.view.Dockerfile
ports:
- "3000:3000"
stdin_open: true
Expand All @@ -29,8 +25,8 @@ services:
build:
context: ./api
dockerfile: api.Dockerfile
volumes:
- ./api:/api
# volumes:
# - ./api:/api
ports:
- "9004:9004"
command: uvicorn main:app --reload --host 0.0.0.0 --port 9004
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ services:
volumes:
- ./view:/view
- ./view/node_modules:/view/node_modules
command: sh -c "yarn && yarn dev"
ports:
- "3000:3000"
stdin_open: true
Expand Down
2 changes: 1 addition & 1 deletion script/down.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker-compose -f docker-compose.prod.yml down
docker compose -f docker-compose.prod.yml down
6 changes: 2 additions & 4 deletions script/up.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
docker-compose -f docker-compose.prod.yml build
docker compose -f docker-compose.prod.yml run --rm view yarn
docker compose -f docker-compose.prod.yml run --rm view yarn build
docker compose -f docker-compose.prod.yml up -d
docker compose -f docker-compose.prod.yml build
docker compose -f docker-compose.prod.yml up -d view api
1 change: 1 addition & 0 deletions view/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const nextConfig = (phase, { defaultConfig }) => {
}

return {
output: "standalone",
/* 開発フェーズを除く全てのフェーズで有効なオプションを設定 */
webpack: (config, options) => {
// ----- ここから本番環境で、console.log を出力しない系の設定 -----
Expand Down
46 changes: 46 additions & 0 deletions view/prod.view.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM node:20.11.1-bookworm-slim AS base

FROM base AS deps

WORKDIR /app

COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi

FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

ENV NEXT_TELEMENTRY_DISABLED 1

RUN \
if [ -f yarn.lock ]; then yarn run build; \
else echo "Lockfile not found." && exit; \
fi

FROM base AS runner
WORKDIR /app

ENV NDOE_ENV production

ENV NEXT_TELEMENTRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000

CMD HOSTNAME="0.0.0.0" node server.js
3 changes: 2 additions & 1 deletion view/view.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM node:20.11.1
FROM node:20.11.1-bookworm-slim

WORKDIR /view
COPY ./ /view

RUN yarn set version stable
RUN yarn install

CMD sh -c "yarn && yarn dev"

0 comments on commit cd082d4

Please sign in to comment.