这是我最终要执行的 *** 作,到目前为止似乎仍然有效,但我仍在研究它:
# script located in bin/runNS=mycompanyPROJECT=myproject# kill and remove old container if it existsdocker kill $PROJECTdocker rm $PROJECT# tag the previously built imagedocker tag $NS/$PROJECT $NS/$PROJECT:old# build the new imagedocker build -t $NS/$PROJECT .# remove the old imagedocker rmi $NS/$PROJECT:olddocker run -dP --name=$PROJECT $NS/$PROJECT /sbin/my_init
在我的项目根目录中,我只需运行:
nodemon -x bin/run
信誉归功于这一来源。
Docker 1.3和Fig的更新
无花果很棒,它确实消除了我以前编写的脚本的很多复杂性。此外,boot2docker现在本机支持使用Virtual
Box的共享文件夹在Mac OS X上安装卷。这是我发现现在非常适合我的东西:
首先,
Dockerfile:
FROM ubuntu:14.04# Replace shell with bash so we can source filesRUN rm /bin/sh && ln -s /bin/bash /bin/sh# Set debconf to run non-interactivelyRUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections# Install base dependenciesRUN apt-get update && apt-get install -y -q --no-install-recommends build-essential ca-certificates curl git libssl-dev python rsync software-properties-common wget && rm -rf /var/lib/apt/lists/*ENV NVM_DIR /usr/local/nvmENV NODE_VERSION 0.10.33# Install nvm with node and npmRUN curl https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash && source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm alias default $NODE_VERSION && nvm use defaultENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modulesENV PATH $NVM_DIR/v$NODE_VERSION/bin:$PATHCMD ["npm", "start"]
的
fig.yml:
app: image: myNodeImage working_dir: /home/myProject volumes_from: - myvols
这是新的
bin/run:
#!/usr/bin/env bash# This is the the bin/run scriptdocker run --rm --volumes-from myvols myNodeImage rsync --delete --recursive --safe-links --exclude .git --exclude node_modules /data/myProject/ /home/myProjectfig up
I also have a
bin/installscript that does the
node_modulesdependency
installs. This assumes I’ve already done an npm install on my host so that any
private packages will work. Also, this works great with npm links, you just
need to make a symlink from your
/home/linkedProjectinto
$NODE_PATH/linkedProjectin your container.
#!/usr/bin/env bash# This is the the bin/install scriptdocker run --rm --volumes-from myvols myNodeImage rm -rf /home/myProject && rsync --delete --recursive --safe-links --exclude .git /data/myProject/ /home/myProject && cd /home/myProject && npm rebuild
So, to put this all together, here’s the steps in order:
- Create my data volume container:
docker run -v $HOME/data:/data:ro -v /home -v /path/to/NODE_PATH --namemyvols myNodeImage echo Creating my volumes
Run my install script:
cd ~/data/myProject && ./bin/install
Run my run script:
nodemon -x bin/run
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)