docker runを使って、Next.jsやGatsbyなんかをgenerateしてみるヘ(^o^)ノ


Nodeのdocker imageでgenerate


$ docker run -it -w '/app' -v $PWD:/app node:15.5.1-alpine3.12 [command]


$ cd dev   # ~/devにコードやらなんやらがある
$ docker run -it -w '/app' -v $PWD:/app node:15.5.1-alpine3.12 npx create-next-app my-app
$ ls -al


$ cd dev
$ docker run -it -w '/app' -v $PWD:/app node:15.5.1-alpine3.12 npm init gatsby
Command failed with ENOENT: git clone /app/my-gatsby-site --recursive --depth=1 --quiet
spawn git ENOENT
npm notice 
npm notice New minor version of npm available! 7.3.0 -> 7.4.0
npm notice Changelog:
npm notice Run npm install -g npm@7.4.0 to update!
npm notice 
npm ERR! code 1
npm ERR! path /app
npm ERR! command failed
npm ERR! command sh -c create-gatsby

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-01-12T11_21_15_546Z-debug.log

templateをgit cloneしてくるところで怒られました


$ docker run -it -w '/app' -v $PWD:/app node:15.5.1-alpine3.12 /bin/sh
/app # git -v
/bin/sh: git: not found



# ~/docker-images/node-dev/15.5.1-alpine3.12/Dockerfile
FROM node:15.5.1-alpine3.12 
RUN apk update --no-cache && \
    apk upgrade --no-cache && \
    apk --no-cache add git


$ docker build -t node-dev:15.5.1-alpine3.12 ~/docker-images/node-dev/15.5.1-alpine3.12/
$ docker run -it -v $PWD:/app node-dev:15.5.1-alpine3.12 npm init gatsby
What would you like to call your site?                                                                                                                                                                                                                                                                                        
✔ · My Gatsby Site                                                                                                                                                                                                                                                                                                            
What would you like to name the folder where your site will be created?                                                                                                                                                                                                                                                       
✔ app/ my-gatsby-site                                                                                                                                                                                                                                                                                                         
✔ Will you be using a CMS?                                                                                                                                                                                                                                                                                                    
· Netlify CMS                                                                                                                                                                                                                                                                                                                 
✔ Would you like to install a styling system?                                                                                                                                                                                                                                                                                 
· Emotion                                                                                                                                                                                                                                                                                                                     
✔ Would you like to install additional features with other plugins?                                                                                                                                                                                                                                                           
· Add Markdown and MDX support                                                                                                                                                                                                                                                                                                
Thanks! Here's what we'll now do:                                                                                                                                                                                                                                                                                             
    🛠  Create a new Gatsby site in the folder my-gatsby-site                                                                                                                                                                                                                                                                  
    📚 Install and configure the plugin for Netlify CMS                                                                                                                                                                                                                                                                       
    🎨 Get you set up to use Emotion for styling your site                                                                                                                                                                                                                                                                    
    🔌 Install gatsby-plugin-mdx                                                                                                                                                                                                                                                                                              
✔ Shall we do this? (Y/n) · Yes                                                                                                                                                                                                                                                                                               
✔ Created site from template                                                                                                                                                                                                                                                                                                  
✔ Installed Gatsby                                                                                                                                                                                                                                                                                                            
✔ Installed plugins                                                                                                                                                                                                                                                                                                           
✔ Created site in my-gatsby-site                                                                                                                                                                                                                                                                                              
🔌 Setting-up plugins...                                                                                                                                                                                                                                                                                                      
║                                                                        ║                                                                                                                                                                                                                                                    
║   Gatsby collects anonymous usage analytics                            ║                                                                                                                                                                                                                                                    
║   to help improve Gatsby for all users.                                ║                                                                                                                                                                                                                                                    
║                                                                        ║                                                                                                                                                                                                                                                    
║   If you'd like to opt-out, you can use `gatsby telemetry --disable`   ║                                                                                                                                                                                                                                                    
║   To learn more, checkout                 ║                                                                                                                                                                                                                                                    
║                                                                        ║                                                                                                                                                                                                                                                    
info Adding gatsby-plugin-netlify-cms                                                                                                                                                                                                                                                                                         
info Adding gatsby-plugin-emotion                                                                                                                                                                                                                                                                                             
info Adding gatsby-plugin-mdx                                                                                                                                                                                                                                                                                                 
info Adding gatsby-source-filesystem                                                                                                                                                                                                                                                                                          
info Installed gatsby-plugin-netlify-cms in gatsby-config.js                                                                                                                                                                                                                                                                  
success Adding gatsby-plugin-netlify-cms to gatsby-config - 0.157s                                                                                                                                                                                                                                                            
info Installed gatsby-plugin-emotion in gatsby-config.js                                                                                                                                                                                                                                                                      
success Adding gatsby-plugin-emotion to gatsby-config - 0.153s                                                                                                                                                                                                                                                                
info Installed gatsby-plugin-mdx in gatsby-config.js                                                                                                                                                                                                                                                                          
success Adding gatsby-plugin-mdx to gatsby-config - 0.161s                                                                                                                                                                                                                                                                    
info Installed pages in gatsby-config.js                                                                                                                                                                                                                                                                                      
success Adding gatsby-source-filesystem (pages) to gatsby-config - 1.213s                                                                                                                                                                                                                                                     
*** Please tell me who you are.                                                                                                                                                                                                                                                                                               
  git config --global ""                                                                                                                                                                                                                                                                            
  git config --global "Your Name"                                                                                                                                                                                                                                                                                   
to set your account's default identity.                                                                                                                                                                                                                                                                                       
Omit --global to set the identity only in this repository.

Initial git commit failed - removing git support

🎉  Your new Gatsby site My Gatsby Site has been successfully created
at /app/my-gatsby-site.
Start by going to the directory with

  cd my-gatsby-site

Start the local development server with

  npm run develop

See all commands at



CMDを上書きする場合は、docker run コマンドのあとにつらつら追加していけばOKです




$ docker run --entrypoint npx -it node:15.5.1-alpine3.12 -v

no more runtime on localhost ヘ(^o^)ノ