Created
April 10, 2024 18:43
-
-
Save ThinaticSystem/1b4e6146d9e54834b1c223e5c1a6d8a8 to your computer and use it in GitHub Desktop.
docker練習
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | |
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile | |
{ | |
"name": "Existing Dockerfile", | |
"build": { | |
// Sets the run context to one level up instead of the .devcontainer folder. | |
"context": "..", | |
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. | |
"dockerfile": "../Dockerfile", | |
// "target": "devcontainer" | |
"target": "deploy" | |
}, | |
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind", | |
"workspaceFolder": "/workspace" | |
// Features to add to the dev container. More info: https://containers.dev/features. | |
// "features": {}, | |
// Use 'forwardPorts' to make a list of ports inside the container available locally. | |
// "forwardPorts": [], | |
// Uncomment the next line to run commands after the container is created. | |
// "postCreateCommand": "cat /etc/os-release", | |
// Configure tool-specific properties. | |
// "customizations": {}, | |
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. | |
// "remoteUser": "devcontainer" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
frontend/node_modules | |
frontend/.next |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | |
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile | |
{ | |
"name": "Existing Dockerfile", | |
"build": { | |
// Sets the run context to one level up instead of the .devcontainer folder. | |
"context": "..", | |
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. | |
"dockerfile": "../Dockerfile", | |
// "target": "devcontainer" | |
"target": "deploy" | |
}, | |
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind", | |
"workspaceFolder": "/workspace" | |
// Features to add to the dev container. More info: https://containers.dev/features. | |
// "features": {}, | |
// Use 'forwardPorts' to make a list of ports inside the container available locally. | |
// "forwardPorts": [], | |
// Uncomment the next line to run commands after the container is created. | |
// "postCreateCommand": "cat /etc/os-release", | |
// Configure tool-specific properties. | |
// "customizations": {}, | |
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. | |
// "remoteUser": "devcontainer" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [ubuntu-base] | |
FROM ubuntu:22.04 AS ubuntu-base | |
# [nodejs-provider] | |
FROM node:20-slim AS nodejs-provider | |
# [ubuntu-nodejs] | |
FROM ubuntu-base AS ubuntu-nodejs | |
# Node.js | |
COPY --from=nodejs-provider /usr/local/include/ /usr/local/include/ | |
COPY --from=nodejs-provider /usr/local/lib/ /usr/local/lib/ | |
COPY --from=nodejs-provider /usr/local/bin/ /usr/local/bin/ | |
# [frontend-dependencies-provider] | |
FROM ubuntu-nodejs AS frontend-dependencies-provider | |
# catalog | |
COPY ./frontend/package.json ./frontend/package-lock.json /workspace/ | |
# Install | |
WORKDIR /workspace/ | |
RUN \ | |
--mount=type=cache,target=~/.npm \ | |
npm ci --include dev | |
# [build-provider] | |
FROM ubuntu-nodejs AS build-provider | |
# dependencies | |
COPY --from=frontend-dependencies-provider /workspace/node_modules/ /workspace/node_modules/ | |
# sources | |
COPY . /workspace/ | |
# Build | |
WORKDIR /workspace/frontend/ | |
RUN npm run build | |
# -------- # | |
# [deploy] # | |
# -------- # | |
FROM ubuntu-nodejs AS deploy | |
# built | |
COPY --from=build-provider /workspace/frontend/package.json /workspace/frontend/ | |
COPY --from=build-provider /workspace/frontend/.next/ /workspace/frontend/.next/ | |
# PM2 | |
RUN \ | |
--mount=type=cache,target=~/.npm \ | |
npm install --global pm2 | |
# Start | |
ENTRYPOINT pm2 start npm --name "nextjs" -- start | |
# -------------- # | |
# [devcontainer] # | |
# -------------- # | |
FROM mcr.microsoft.com/devcontainers/base:ubuntu-22.04 AS devcontainer | |
# Node.js | |
COPY --from=nodejs-provider /usr/local/include/ /usr/local/include/ | |
COPY --from=nodejs-provider /usr/local/lib/ /usr/local/lib/ | |
COPY --from=nodejs-provider /usr/local/bin/ /usr/local/bin/ | |
# dependencies | |
COPY --from=frontend-dependencies-provider /workspace/node_modules/ /workspace/node_modules/ | |
# Start | |
ENTRYPOINT npm run dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @type {import('next').NextConfig} */ | |
const nextConfig = { | |
output: 'standalone' | |
}; | |
export default nextConfig; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment