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.
macOS High Sierra v10.13.6 Docker version 19.03.8 docker-compose version 1.25.5
I want to complete everything on docker
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
FROM node:14.15.3-alpine WORKDIR /usr/src/app
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.
$ docker-compose run --rm node npm install create-next-app
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
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
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.