refactor to allow better integration between container and local command line

This commit is contained in:
Adam Brown 2015-02-15 16:17:28 -05:00
parent 4470b9caef
commit ee54bae9d9
8 changed files with 88 additions and 142 deletions

View File

@ -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

View File

@ -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 <command>`. 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

16
default-packages.sh Normal file
View File

@ -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

19
mean Executable file
View File

@ -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 $@

View File

@ -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

View File

@ -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

37
start-mongodb Executable file
View File

@ -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

97
startup
View File

@ -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"