通过厨师与分阶段文件安装docker集装箱

所以我一直在为这个问题奋斗了几天,但我觉得这应该是一个简单的解决办法(这可能是我对厨师或厨师docker食谱的误解)。

这是我的场景。 我有一组容器来托pipe我的应用程序的组件。 我有一个工作stream程,基本上不断地在不同的环境中部署这些容器,每个容器都有不同的设置(例如,Dev将所有的容器都存放在一个虚拟机上,但是对于Staging / Prod,容器将分散在不同的VM /硬件上)。

我试图使用厨师通过刀部署这些容器,然后在虚拟机上运行一套食谱。 我的问题是,我不知道如何部署Dockerfile的COPY命令的阶段文件。 这里是我正在使用的一个示例Dockerfile。 COPY命令应该将package.json和index.js文件复制到/ src目录并执行npm。

FROM ubuntu:14.04 # Install dependencies and nodejs RUN apt-get update -y RUN apt-get install -y python-software-properties python g++ make curl RUN curl -sL https://deb.nodesource.com/setup | sudo bash - RUN apt-get update -y RUN apt-get install -y build-essential nodejs # Bundle app source COPY . /src # Install app source RUN cd /src; ls; npm install EXPOSE 8080 CMD ["node", "/src/index.js"] 

我的食谱的default.rb看起来像这样:

 include_recipe 'docker' docker_image_build_file = '/tmp/docker_image_build.dockerfile' cookbook_file "/etc/chef/package.json" do source 'package.json' action :create_if_missing end cookbook_file "/etc/chef/index.js" do source 'index.js' action :create_if_missing end cookbook_file docker_image_build_file do source 'Dockerfile' end docker_image 'node' do tag 'nodeTag' source docker_image_build_file action :build end docker_container 'node' do detach true port '8080:8888' end 

我试图在一堆地方放置文件,包括docker / chef /目录,chef /目录和files / default /目录。 没有东西被抄袭。 在COPY命令后的docker文件中的“ls”调用只打印“Dockerfile”,显然npm安装失败,因为它在/ src目录下找不到package.json:

 <server> Step 14 : RUN cd /src; ls; npm install <server> ---> Running in 5f1dba1fd0cf <server> Dockerfile <server> npm ERR! install Couldn't read dependencies <server> npm ERR! package.json ENOENT, open '/src/package.json' <server> npm ERR! package.json This is most likely not a problem with npm itself. <server> npm ERR! package.json npm can't find a package.json file in your current directory. <server> <server> npm ERR! System Linux 3.13.0-37-generic <server> npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" <server> npm ERR! cwd /src <server> npm ERR! node -v v0.10.33 <server> npm ERR! npm -v 1.4.28 <server> npm ERR! path /src/package.json <server> npm ERR! code ENOPACKAGEJSON <server> npm ERR! errno 34 <server> npm ERR! <server> npm ERR! Additional logging details can be found in: <server> npm ERR! /src/npm-debug.log <server> npm ERR! not ok code 0 

我知道我可能做的很愚蠢,所以任何帮助将不胜感激!

PS我意识到,在部署Dockerfiles中还有其他几个选项,但是我真的很想利用厨师,因为除了部署和启动容器之外,我还有几个食谱要用来准备我的环境。

只是在这里发表,以防其他人遇到这个问题。 发生这种情况是因为我在docker_image中的源代码实际上应该是一个指向/ tmp的目录,并且我复制了那里的所有文件。 这是我更新(工作)的食谱:

 include_recipe 'docker' docker_node_data = '/tmp/docker' directory docker_node_data do action :create end cookbook_file "#{docker_node_data}/package.json" do source 'package.json' action :create_if_missing end cookbook_file "#{docker_node_data}/Dockerfile" do source 'Dockerfile' end docker_image 'example/node' do tag 'latest' source docker_node_data action :build end docker_container 'example/node' do detach true port '8080:8080' action :run end