フリーランス 技術調査ブログ

フリーランス/エンジニア Ruby Python Nodejs Vuejs React Dockerなどの調査技術調査の備忘録

dockerでgatsbyの環境を構築する

Dockerfile

※ 下記のファイルだけではdokerは起動しません。nginxの設定ファイルをコピーする処理をしているため

FROM amazonlinux:latest

RUN yum update -y

## nginx
RUN yum install -y amazon-linux-extras
RUN amazon-linux-extras install nginx1
RUN systemctl enable nginx

COPY ./nginx.conf /etc/nginx/

## nodejs
RUN curl -sL https://rpm.nodesource.com/setup_14.x | bash -
RUN yum install nodejs -y
RUN yum -y install wget
RUN wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
RUN yum -y install yarn

## gatsby cli
RUN yarn global add gatsby-cli

WORKDIR /srv/frontend/app

gatsbyインストール

yarn global add gatsby-cli

プロジェクトの作成

 gatsby new <プロジェクト名>

※ gitがインストールされていないとエラーになる

info Creating new site from git: https://github.com/gatsbyjs/gatsby-starter-default.git
ERROR 
Command failed with ENOENT: git clone https://github.com/gatsbyjs/gatsby-starter-default.git hoge --recursive --depth=1
spawn git ENOENT
Error: Command failed with ENOENT: git clone https://github.com/gatsbyjs/gatsby-starter-default.git hoge --recursive --depth=1
spawn git ENOENT

サーバーの起動

  • サーバー起動
# gatsby develop
  • http://localhost:8000/___graphqlにアクセスするとgraphqlが利用できることが確認できる f:id:PX-WING:20210115101359p:plain