Skip to content

Instantly share code, notes, and snippets.

@mscottford
Last active January 31, 2018 03:52
Show Gist options
  • Save mscottford/52ad9741b929169bef72af17cdcbe6ac to your computer and use it in GitHub Desktop.
Save mscottford/52ad9741b929169bef72af17cdcbe6ac to your computer and use it in GitHub Desktop.
Docker and docker-compose setup for a simple node environment which is setup to support using `yarn` and `yo`

Run Yarn and Yeoman in a Docker container

Part of my mission to not install any dev tools or dev environments outside of Docker.

Build container

Run docker-compose build.

Get a bash prompt in the container

Run docker-compose run app bash.

Start a new project with yarn

Either:

docker-compose run app bash
yarn init

or:

docker-compose run app yarn init

Adding additonal yeoman generators:

  1. Modify Dockerfile to globally include additional generators

    • example: Add RUN yarn globa add generator-exrpess to the end of the Dockerfile
  2. Run docker-compose build to rebuild the container

  3. Either:

    docker-compose run app bash
    yo express
    

    or:

    docker-compose run app yo express
    
version: "2"
services:
app:
build: .
working_dir: /home/docker/app
environment:
- NODE_ENV=production
volumes:
- ./:/home/docker/app
FROM node:9.3
RUN apt-get update
RUN apt-get install sudo
RUN adduser --disabled-password --gecos '' docker
RUN adduser docker sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER docker
RUN sudo apt-get update
RUN sudo apt-get install apt-transport-https
RUN sudo curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
RUN sudo echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
RUN sudo apt-get update
RUN sudo apt-get install yarn
ENV PATH=/home/docker/.yarn/bin:$PATH
RUN yarn global add yo
@joshkel
Copy link

joshkel commented Jan 19, 2018

Nitpick: "Yeoman," not "Yoeman."

(I need to learn Docker. Thanks for the reminder.)

@mscottford
Copy link
Author

Thanks for pointing that out! I've updated it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment