![]() ![]() Let's check that the build is there: ▶ docker image ls react:app Then you probably want the repository to be something unique. It doesn't matter so much what it is unless you're going to upload your container the a registry. Now let's build it: ▶ docker image build -t react:app. That's so that when you simply run the container the default thing it does is to run yarn start. Yarn test as a point of convenience, note that the default CMD is "start". # then react-scripts won't clear the console. # The '| cat' is to trick Node that this is an non-TTY terminal That's a file we need to create too, alongside the Dockerfile file. Note how the ENTRYPOINT points to run.sh. If you didn't do this, the node_modules directory would be part of the mounted volume which not only slows down Docker (since there are so many files) it also isn't necessary to see those files. That's so that it doesn't get added in "here" (i.e. Note how the NODE_PATH environment variable puts the node_modules in the root of the container. That gives you a Node and Yarn by default. This Dockerfile is the minimum: FROM node:8įirst of all we're basing this on the official Node v8 repository on Docker Hub. Instead, when building the image we're going let node_modules stay inside the image. We won't need the node_modules here in the project directory. README.md node_modules package.json public src yarn.lock If you haven't already, install create-react-app globally: ▶ yarn global add create-react-appĪnd, once installed, create a new project: ▶ create-react-app docker-create-react-app Let's look at all three but using Docker. So there are three main things you want to do with create-react-app dev server, running tests and creating build artifacts. Why would you want to use Docker to do React app work? Isn't Docker for server-side stuff like Python and Golang etc? No, all the benefits of Docker apply to JavaScript client-side work too.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |