Grommet Docker Basic
This is a basic Grommet project (using the sample-app generated by Grommet) running in a Docker container configuration.
First, build your custom Docker image from the
Dockerfile. In this case I'm tagging it with
lodgik/grommet but you can
use any name you like for your new image.
docker build -t lodgik/grommet .
Once the image is built, run a Docker container from that image. Be sure to update the command below with whatever name you chose for your custom image in the above command.
docker run --name grommet -d -p 9000:9000 lodgik/grommet
Using Docker Compose
Docker Compose lets us script and automate the Docker image build and container spin up. It's very convenient if you want to avoid using the command line constantly.
To use compose, simply execute this command:
docker-compose up -d. The
-d option allows the new container to run in the background.
It pulls configuration from the
docker-compose.yml file and generally does the same thing as the two Docker commands in the Dockerfile section above.
- This configuration uses the official Node Docker image 6.9.4 (you can update the version in the Dockerfile)
- Do not try to use the Docker node-alpine images. Because Grommet uses node-sass the way it does, you'll get compilation errors when building the Grommet Docker image
- In this example, I used the Grommet
sample-appwhich is generated as described in the Grommet Getting Started documentation
- I use Node Express to serve the static index.html file generated from Grommet's distribution files. I did this for simplicity. Not necessarily a good option for your production needs.
- You'll see a ton of command line output during build. This is coming frrom a setting in the base Node Docker image. You can ignore it.
If you're not using Grommet's
gulp dist option, you can remove those related RUN commands from the Dockerfile. They are specific to this configuration.
Also you'll notice a RUN command in the Dockefile -
RUN npm rebuild firstname.lastname@example.org. This forces node-sass to be built for the container's platform. Since it's
a binary, I do this to ensure that node-sass is properly built before running
npm install. I will be testing to see if this can be removed, but haven't had the time yet.
Thank you to Ejaz for asking me about an issue he was having with Node on Alpine which inspired me to create this solution.