-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docker to yeoman generator #200
Changes from all commits
5f7f60f
1f97b34
1df765d
12be333
b4fa999
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM node:slim | ||
|
||
EXPOSE 3000 | ||
ENV NODE_ENV=docker-dev | ||
VOLUME /www |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,62 @@ Very simple example project for `react-server` which only shows server rendering | |
|
||
To start in development mode: | ||
|
||
``` | ||
```shell | ||
npm start | ||
``` | ||
|
||
Then go to [localhost:3000](http://localhost:3000/). You will see a simple page that pre-renders and that is interactive on load. It also will include hot reloading of React components in their own file. | ||
|
||
If you want to optimize the client code at the expense of startup time, type `NODE_ENV=production npm start`. You can also use any of [the other arguments for react-server-cli](../../react-server-cli#setting-options-manually) after `--`. For example: | ||
|
||
``` | ||
```shell | ||
# start in dev mode on port 4000 | ||
npm start -- --port=4000 | ||
``` | ||
|
||
# Developing using Docker and Docker Compose | ||
|
||
These steps assume you are familiar with docker and already have it installed. Some basics: | ||
|
||
1. Download [Docker Toolbox](https://www.docker.com/products/docker-toolbox) and install it. | ||
2. Start `docker quick start shell` | ||
3. Navigate to where you generated the project | ||
4. Add a configuration to set the `host` option to the ip given by `docker-machine ip`. An example configuration might be like: | ||
```json | ||
{ | ||
"port": "3000", | ||
"env": { | ||
"docker": { | ||
"host": "Your ip from `docker-machine ip` here" | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is cool. Nice use of environment configuration. Thanks for the added documentation. Clears it right up for me. |
||
"staging": { | ||
"port": "3000" | ||
}, | ||
"production": { | ||
"port": "80" | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just occurred to me that we should probably generate this config. #203 |
||
``` | ||
5. Now that your system is ready to go, start the containers: | ||
```shell | ||
docker-compose build --pull | ||
docker-compose up | ||
``` | ||
|
||
The containers will now be running. At any time, press ctrl+c to stop them. | ||
|
||
To clean up, run the following commands: | ||
|
||
```shell | ||
docker-compose stop | ||
docker-compose rm --all | ||
docker volume ls # and get the name of the volume ending in react_server_node_modules | ||
docker volume rm _react_server_node_modules # this name will be different depending on the name of the project | ||
``` | ||
|
||
The configuration included stores the node_modules directory in a "named volume". This is a special | ||
persistent data-store that Docker uses to keep around the node_modules directory so that they don't have to | ||
be built on each run of the container. If you need to get into the container in order to investigate what | ||
is in the volume, you can run `docker-compose exec react_server bash` which will open a shell in the | ||
container. Be aware that the exec functionality doesn't exist in Windows (as of this writing). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: '2' | ||
services: | ||
react_server: # The label of the service | ||
build: . # The location of the Dockerfile to build | ||
volumes: # Files to share with the container and the host | ||
- .:/www # Share the project in /www in the container | ||
- react_server_node_modules:/www/node_modules # A special volume so that OS specific node_modules are built correctly | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, thanks for renaming the volume, too. Didn't even catch that one. |
||
working_dir: /www # The location all commands should run from | ||
environment: | ||
NODE_ENV: 'docker' # Set the NODE_ENV environment variable | ||
command: /bin/bash -c "npm install && npm start" # The command to run in when the container starts | ||
ports: # Ports to expose to your host | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these comments are really helpful! |
||
- '3000:3000' | ||
- '3001:3001' | ||
# An example database | ||
# my_db: | ||
# image: rethinkdb:latest | ||
# You can reference the db/service by using the dns name `my_db` and docker will do the rest | ||
|
||
# Volume to store separate from the container runtime and host | ||
volumes: | ||
react_server_node_modules: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Nice to have syntax coloring on these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks for adding this!