I want to docker-compose up Next.js!

Introduction

Recently, I have noticed that if the development environment can be completed with docker, the local can be kept clean, so I tend to want to do it with Docker. So, I launched the topic Next.js with docker-compose, so I will leave it as a memorandum for myself.

environment

macOS High Sierra v10.13.6
Docker version 19.03.8
docker-compose version 1.25.5

Implementation

I want to complete everything on docker

Preparation

Create a new project directory and place the following two files under it. Dockerfile and docker-compose.yml. Change the directory move command in command in docker-compose.yml according to the name of the project. This time, let's call it sample-app.

Dockerfile


FROM node:14.15.3-alpine
WORKDIR /usr/src/app

docker-compose.yml


version: '3'
services:
  node:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ./:/usr/src/app
    command: sh -c "cd sample-app && npm run dev"
    ports:
      - "3000:3000"

The current situation

$ ls
Dockerfile  docker-compose.yml

Install the create-next-app command

Install the create-next-app command.

$ docker-compose run --rm node npm install create-next-app

Execute the create-next-app command

This will create the next app. Unlike create-react-app, create-next-app does not seem to be able to specify the installation directory, so make sure that the app name is the same as the directory name specified by command in docker-compose.yml. (Please let me know if you can specify the installation directory.)

$ docker-compose run --rm node npx create-next-app sample-app

run docker-compose up

Once you have successfully installed the next-app, you should be able to launch the app. If you get Welcomet to Next.js!, You are successful.

$ docker-compose up

スクリーンショット 2021-01-01 17.43.53.png

At the end

This time, I built a development environment for next.js using docker-compose. I think that docker-compose is very convenient because it can be linked with API containers. I wonder if the create-next-app command can also specify a directory.

Recommended Posts

I want to docker-compose up Next.js!
I want to convert characters ...
I want to use FormObject well
I want to convert InputStream to String
I want to easily back up files used at work
I want to pass the startup command to postgres with docker-compose.
I want to develop a web application!
I want to write a nice build.gradle
I want to eliminate duplicate error messages
I want to make an ios.android app
I want to use DBViewer with Eclipse 2018-12! !!
I want to RSpec even at Jest!
I want to write a unit test!
I want to install PHP 7.2 on Ubuntu 20.04.
I want to stop Java updates altogether
I want to use @Autowired in Servlet
I want to target static fields to @Autowired
I want to do team development remotely
I want to test Action Cable with RSpec test
I want to sort by tab delimited by ruby
I want to output the day of the week
Run R from Java I want to run rJava
I want to send an email in Java.
I want to graduate from npm install properly [2020]
I want to use arrow notation in Ruby
I tried to link grafana and postgres [docker-compose]
[Ruby] I want to do a method jump!
I want to use java8 forEach with index
I want to var_dump the contents of the intent
I want to pass APP_HOME to logback in Gradle
I want to simply write a repeating string
I want to design a structured exception handling
rsync4j --I want to touch rsync in Java.
I want to play with Firestore from Rails
[Xcode] I want to manage images in folders
I want to be eventually even in kotlin
I want to write quickly from java to sqlite
I want to truncate after the decimal point
I can't do docker-compose up -d with docker
I want to reduce simple mistakes. To command yourself.
I want to perform aggregation processing with spring-batch
[Rails] I want to load CSS with webpacker
I want to delete files managed by Git
I want to get the value in Ruby
I want to use Combine in UIKit as well.
I want to call a method of another class
What is `docker-compose up`?
I want to do something like "cls" in Java
[Java] I want to calculate the difference from the date
I want to use NetBeans on Mac → I can use it!
I want to embed any TraceId in the log
Pointcut Expression I want to specify more than one
I started MySQL 5.7 with docker-compose and tried to connect
I learned stream (I want to convert List to Map <Integer, List>)
I want to judge the range using the monthly degree
I want to use a little icon in Rails
I want to know the answer of the rock-paper-scissors app
I want to display the name of the poster of the comment
I want to dark mode with the SWT app
I want to monitor a specific file with WatchService
I want to apply ContainerRelativeShape only to specific corners [SwiftUI]