Skip to content

docker create-react-app without installing node, npm in local system. #3002

@przbadu

Description

@przbadu

Because we are using Docker, we should not install node, npm, create-react-app
in our development machine, not even for generating create-react-app scaffold.

For this purpose I am using 2-step docker configuration:

  • In first step, we will create a simple docker container, that does only one thing, install create-react-app
    and we can use it to generate create-react-app scaffold.
  • And second docker configuration is project specific. It will handle nodemon, npm, development servers, etc.

Build docker image for create-react-app

Because we are not installing create-react-app locally in our development machine, Let's build new docker container for it.

Dockerfile

FROM node:8.2.1-alpine
RUN npm install -g create-react-app \
                   create-react-native-app \
                   react-native-cli
RUN mkdir /app
WORKDIR /app
ADD . /app

my failed attempt to solve this problem without docker-compose

NOTE: we need to fix this problem, please help me if anyone know the solution.

  1. build the docker image that will handle just react cli part.
docker build . -t react-cli
  1. Once that is done, let's generate new create-react-app scaffold using this image:
docker run react-cli create-react-app myApp

EXPECTED

  • it should generate react scaffold app myApp in my current directory.

RESULT

Got nothing 😄 . Looks like it is generating app inside docker container.

Working Solution: using docker-compose

Because I was unable to solve it by using just docker command, I am solving it using
docker-compose.

docker-compose.yml

version: '3'
services:
  web:
    build: .
    image: react-cli
    container_name: react-cli
    volumes:
      - .:/app

Usage

Now using docker-compose we can generate our react application:

docker-compose run web create-react-app myApp

Everthing should work this time. And you should get react generated application inside myApp
directory.

If anyone knows how to use react-cli image to generate create-react-app without using docker-compose.yml file, please let me know.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions