どのように私は私の次の博士.JSウェブサイト?


開発と生産のためにイメージを作成するためにDockerを使う方法を学んでください.
あなたは完全な本格的なアプリケーションを開発し、他の開発者がプロジェクトに貢献することを想像してください.アプリケーションがUI、実行中のサーバー、データベースなどのような異なるコンポーネントから構成されている場合、新しい開発者は、開発を開始する前に、システム全体にスタック全体の正確な構成をインストールする必要があります.この問題を克服するためにDockerは救助に来る.

何がDockerですか?
Dockerは、開発、出荷、および実行中のアプリケーションのオープンプラットフォームです.あなたがソフトウェアを速く届けることができるように、Dockerはあなたの基盤からあなたのアプリケーションを切り離すことができます.Dockerを使用すると、アプリケーションを管理するのと同じ方法でインフラストラクチャを管理できます.すぐにコードを出荷、テスト、および展開するためのDockerの方法論を利用することによって、コードの書き込みとそれを実行する際の遅延を大幅に減らすことができます.

開発と生産のための多段階Dockerfile
開発と生産の両方に共通のDockerファイルを作成しました.DockerFileは、アプリケーションのイメージを作成するために使用されます.このイメージを使用して、イメージの実行中のバージョンのようなコンテナのN数を作成できます.
🐬Dockerfile
#Creates a layer from node:alpine image.
FROM node:alpine

#Creates directories
RUN mkdir -p /usr/src/app

#Sets an environment variable
ENV PORT 3000

#Sets the working directory for any RUN, CMD, ENTRYPOINT, COPY, and ADD commands
WORKDIR /usr/src/app

#Copy new files or directories into the filesystem of the container
COPY package.json /usr/src/app
COPY package-lock.json /usr/src/app

#Execute commands in a new layer on top of the current image and commit the results
RUN npm install

##Copy new files or directories into the filesystem of the container
COPY . /usr/src/app

#Execute commands in a new layer on top of the current image and commit the results
RUN npm run build

#Informs container runtime that the container listens on the specified network ports at runtime
EXPOSE 3000

#Allows you to configure a container that will run as an executable
ENTRYPOINT ["npm", "run"]

🐙Dockerは簡単にコンテナを作成するために構成します.
UI、ランニングサーバー、DBから構成され、すべてのコンポーネントのコンテナを作成するアプリケーションがあるとします.つの方法は、各コンポーネントのDockerFileを作成し、手動で1つずつコンテナを起動するか、またはDockerのコンポーズを使用して、1つのコマンドでスタック全体を起動することができます.
以下は一般的なDocker構成です.開発と生産のためのYMLファイル
🐬Dockerの作成気象研
version: '3' #This denotes that we are using version 3 of Docker Compose
services: #This section defines all the different containers we will create.
  blog_deepak: #This is the name of our Nextjs application.
    build: #This specifies the location of our Dockerfile
      context: . #This specifies the location of our Dockerfile
    ports: #This is used to map the container’s ports to the host machine.
      - "3000:3000"
🐬Dockerの作成東大物性研
version: "3" #This denotes that we are using version 3 of Docker Compose
    services: #This section defines all the different containers we will create.
    blog_deepak: #This is the name of our Nextjs application.
        command: dev #command to execute
                #This is just like the -v option for mounting disks in Docker. In this              example, we attach our code files directory to the containers’ ./code              directory.  This way, we won’t have to rebuild the images if changes are           made.
        volumes:
            - .:/usr/src/app
            - /usr/src/app/node_modules
            - /usr/src/app/.next
🐬Dockerの作成京大理
version: "3" #This denotes that we are using version 3 of Docker Compose
services: #This section defines all the different containers we will create.
    blog_deepak: #This is the name of our Nextjs application.
        command: prod #command to execute
私はスクリプトをパッケージに設定しました.JSONの構成を実行するJSON.
パッケージ.JSON
"scripts": {
    "dev": "next dev",
    "build": "next build",
    "prod": "next start",
    "dev:up": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml up",
    "prod:up": "docker-compose -f docker-compose.yml -f docker-compose.prod.yml up"
  },
デフォルトでは、2つのファイルを読み込みます.YMLとオプションのdockerが作成されます.オーバーライドします.YMLファイル.コンベンションによって、Dockerは構成します.YMLには、ベースの設定が含まれます.オーバーライドファイルは、その名前が示すように、既存のサービスまたは全く新しいサービスの設定オーバーライドを含めることができます.
複数のオーバーライドファイル、または別の名前のオーバーライドファイルを使用するには、- fオプションを使用してファイルの一覧を指定できます.マージファイルをコマンドラインで指定した順序で作成します.