From ee54bae9d9b25cadd5c174e654658e2a85006322 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Sun, 15 Feb 2015 16:17:28 -0500 Subject: [PATCH] refactor to allow better integration between container and local command line --- Dockerfile | 32 ++++----------- README.md | 12 ++++-- default-packages.sh | 16 ++++++++ mean | 19 +++++++++ mean-dev | 3 -- mount-data | 14 ------- start-mongodb | 37 +++++++++++++++++ startup | 97 --------------------------------------------- 8 files changed, 88 insertions(+), 142 deletions(-) create mode 100644 default-packages.sh create mode 100755 mean delete mode 100644 mean-dev delete mode 100755 mount-data create mode 100755 start-mongodb delete mode 100755 startup diff --git a/Dockerfile b/Dockerfile index 938918a..e3d1217 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,7 @@ RUN apt-get install -y nodejs # install ruby RUN apt-get install -y ruby1.9.1 ruby1.9.1-dev + # add a user RUN useradd -ms /bin/bash docker @@ -28,10 +29,6 @@ USER docker # configure ruby gems to run from the home directory ENV PATH $PATH:/home/docker/.gem/ruby/1.9.1/bin -# install some ruby gems -RUN gem install --user-install sass -RUN gem install --user-install compass - # configure npm to run without sudo permissions RUN echo 'prefix=${HOME}/.npm-packages' >> $HOME/.npmrc @@ -40,27 +37,12 @@ ENV NODE_PATH $NPM_PACKAGES/lib/node_modules:$NODE_PATH ENV PATH $PATH:$NPM_PACKAGES/bin ENV MANPATH $(manpath):$NPM_PACKAGES/share/man -# install yeoman tooling and other npm packages -RUN npm install -g node-gyp -RUN npm install -g yo bower grunt-cli -RUN npm install -g generator-webapp generator-angular generator-angular-fullstack generator-polymer - -# #create a data volume -# actually, let's just leave this to the command line -# VOLUME /data - -# #expose the ports -# actually, let's just leave this to the command line +# the home folder is a volume +# we can mount it to a data volume and then it will be shared with all instances +VOLUME /home/docker + +# expose the ports # EXPOSE 8000 # EXPOSE 9000 # EXPOSE 3000 -# EXPOSE 35729 - -# configure git -RUN git config --global push.default simple -RUN git config --global credential.helper cache -RUN git config --global credential.helper 'cache --timeout=43200' - -# it would be nice if npm packages could be shared between instances... -# however it is difficult to both: add global packages from the Dockerfile -# and at the same time have the packages saved in a volume +# EXPOSE 35729 \ No newline at end of file diff --git a/README.md b/README.md index 7d1bf61..e049159 100755 --- a/README.md +++ b/README.md @@ -2,11 +2,17 @@ A docker container for developing mean stack applications -Useage +Usage ====== -Build the container with `sudo docker build -t 'tag name' .` and run with `sudo ./mean-dev`. Or, start a whole web development stack with `sudo ./startup`. +Build the container with `docker build -t 'tag name' .`. Install the `mean` and `start-mongodb` to `~/bin` or some other location in the path. -To mount the samba filesystem, try `sudo mount -t cifs uid=adamarthurryan forceuid //localserver/_data /mnt/localserver` +To run commands from the container, use `mean `. For example, to install a new npm package globally: + mean npm install -g generator-polymer +Or to create a yeoman scaffolding in the current folder: + mean yo polymer + +Some default npm and gem packages are specified in `default-packages.sh`. They can be installed with: + mean bash default-packages.sh diff --git a/default-packages.sh b/default-packages.sh new file mode 100644 index 0000000..6a6828b --- /dev/null +++ b/default-packages.sh @@ -0,0 +1,16 @@ +#!/bin/bash + + +# default package installations +echo "run this script with 'mean bash default-packages.sh'" + + + +# install some ruby gems +gem install --user-install sass +gem install --user-install compass + +# install yeoman tooling and other npm packages +npm install -g node-gyp +npm install -g yo bower grunt-cli +npm install -g generator-webapp generator-angular generator-angular-fullstack generator-polymer \ No newline at end of file diff --git a/mean b/mean new file mode 100755 index 0000000..9b61e85 --- /dev/null +++ b/mean @@ -0,0 +1,19 @@ +#!/bin/bash + +# launch the mean docker container to execute a single command on the working directory +# the working directory will be mounted as /working in the docker container + + +# test if the data-docker-home container has been created +if docker inspect -f {{.Name}} data-docker-home > /dev/null + then + echo > /dev/null + else + echo "* creating data-docker-home container" + echo + # The data container has a volume at /home/docker, is named 'data' and is based on busybox + docker create -v /home/docker --name data-docker-home adamarthurryan/mean echo "Data container - docker home" + +fi + +docker run -it --rm --volumes-from=data-docker-home -v ${PWD}:/working -w /working -p 9000:9000 -p 35729:25729 adamarthurryan/mean $@ \ No newline at end of file diff --git a/mean-dev b/mean-dev deleted file mode 100644 index 150e626..0000000 --- a/mean-dev +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -docker run -d -it --name=mean-dev --volumes-from=data-files --link=mongodb:mongodb -p=localnum:9000 -p=localnum:34729 -it adamarthurryan/mean-dev \ No newline at end of file diff --git a/mount-data b/mount-data deleted file mode 100755 index 7e6e059..0000000 --- a/mount-data +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - - -# determine the id of the user who invoked this script -# if sudo was used, the user who invoked sudo -if [ ${SUDO_USER} ] - then - REAL_USER=${SUDO_USER} - else - REAL_USER=${USER} -fi - -echo "mounting //localhost_data to /mnt/data with uid:gid ${REAL_USER}:${REAL_USER}" -mount -t cifs //localhost/_data /mnt/data -o uid=${REAL_USER} -o gid=${REAL_USER} -o forceuid -o forcegid diff --git a/start-mongodb b/start-mongodb new file mode 100755 index 0000000..e45cb7e --- /dev/null +++ b/start-mongodb @@ -0,0 +1,37 @@ +#! /bin/bash + +# Start a data container and a mongodb instance + +echo + +# test if the data-db container has been created +if docker inspect -f {{.Name}} data-db + then + echo "* data-db exists" + else + echo "* creating data-db" + # The data container has a volume at /data/db, is named 'data' and is based on mongo + docker create -v /data/db --name data-db mongo echo "Data container - database" +fi + +echo + +# test if the mongo db server has been created +if docker inspect -f {{.Name}} mongodb + then + # make sure the server is running + if docker inspect -f {{.State.Running}} mongodb + then + echo "* mongodb exists and is running" + else + echo "* starting mongodb" + docker start mongodb + fi + else + echo "* creating new mongodb server" + # Start a mongo db server as a daemon + # The server will use the data-db container as a volume + docker run -p 27017 --name=mongodb --volumes-from=data-db -d mongo +fi + + diff --git a/startup b/startup deleted file mode 100755 index 694ec00..0000000 --- a/startup +++ /dev/null @@ -1,97 +0,0 @@ -#! /bin/bash - -echo "* this script must be run as super user" - -# Start a data container, an ssh server, a mongodb instance and a samba server - -echo - -# test if the data-db container has been created -if docker inspect -f {{.Name}} data-db - then - echo "* data-db exists" - else - echo "* creating data-db" - # The data container has a volume at /data/db, is named 'data' and is based on busybox - docker create -v /data/db --name data-db busybox echo "Data container - database" -fi - -echo - -# test if the mongo db server has been created -if docker inspect -f {{.Name}} mongodb - then - # make sure the server is running - if docker inspect -f {{.State.Running}} mongodb - then - echo "* mongodb exists and is running" - else - echo "* starting mongodb" - docker start mongodb - fi - else - echo "* creating new mongodb server" - # Start a mongo db server as a daemon - # The server will restart automatically on boot and will use the data-db container as a volume - docker run -p 27017 --name=mongodb --volumes-from=data-db -d mongo -fi - -echo - -# test if the data-files container has been created -if docker inspect -f {{.Name}} data-files - then - echo "* data-files exists" - else - echo "* creating data-files" - # The data container has a volume at /data/db, is named 'data' and is based on busybox - docker create -v /data --name data-files busybox echo "Data container - files" - - # To connect a client to this server we would: - # sudo docker run --link=mongodb:mongodb -i mongo mongo --host mongodb -fi - -echo - -#make sure the samba server is running -if docker inspect -f {{.State.Running}} samba-server - then - echo "* samba-server running" - else - # create the samba server - echo "* creating samba server" - sudo docker run --rm -v $(which docker):/docker -v /var/run/docker.sock:/docker.sock svendowideit/samba data-files -fi - -echo - -# test if the mean-dev container has been created -if docker inspect -f {{.Name}} mean-dev - then - # make sure the server is running - if docker inspect -f {{.State.Running}} mean-dev - then - echo "* mean-dev exists and is running" - else - echo "* starting mean-dev" - fi - else - echo "* creating mean-dev" - docker run -d --name=mean-dev --volumes-from=data-files --link=mongodb:mongodb -p=8000:8000 -p=9000:9000 -p=3000:3000 -p=35729:35729 -it adamarthurryan/mean-dev -fi - -echo -echo -echo "* to attach to the mean-dev server: " -echo "> sudo docker attach mean-dev" -echo -echo "* to run an instance for access to tools:" -echo "> sudo docker run --volumes-from=data-files --rm -it adamarthurryan/mean-dev" - -echo -echo "* or maybe you want another dev server:" -echo "docker run -d --name=thename --volumes-from=data-files --link=mongodb:mongodb -p=localnum:9000 -p=localnum:34729 -it adamarthurryan/mean-dev" - -echo -echo "* mount the data folder with ./mount-data" -