迷你康达环境的Docker多阶段构建

时间:2019-03-15 14:58:35

标签: python docker

我想从现有的conda环境中进行多阶段构建? 不幸的是,一旦复制到新映像中,它会答复/ bin / python不起作用:/bin/sh python: not found当我启动容器时。

是否有任何技巧可以减少python脚本的图像占用空间?

这里有一个示例文件:

FROM custom_image as build

....

RUN conda env create -n my_env -f env.yml

FROM python:alpine

COPY --from=build /opt/conda/ens/my_env /opt/conda/ens/my_env 
COPY other files

CMD /opt/conda/ens/my_env/bin/pyton my_script
EXPOSE 8080

1 个答案:

答案 0 :(得分:0)

复制整个FROM python:alpine COPY --from=build /opt/conda/. /opt/conda/ COPY other files ENV PATH /opt/conda/bin:$PATH CMD python my_script EXPOSE 8080 目录并设置PATH环境对我来说很有效。就您而言,请尝试以下操作:

var property = {
	"data": [{
		"ID": "123456",
		"name": "Coleridge st",
		"criteria": [
			{
				"type": "type1",
				"name": "name1",
				"value": "7",
				"properties": []
			},
			{
				"type": "type2",
				"name": "name2",
				"value": "6",
				"properties": [
					{
						"type": "MAX",
						"name": "one",
						"value": "100"
					}, {
						"type": "MIN",
						"name": "five",
						"value": "5"
					}

				]
			},
			{
				"type": "type3",
				"name": "name3",
				"value": "5",
				"properties": [{
					"type": "MAX1",
					"name": "one6",
					"value": "1006"
				}, {
					"type": "MIN2",
					"name": "five6",
					"value": "56"
				}]
			}
		]
	},
	{
		"ID": "456789",
		"name": "New Jersy",
		"criteria": [
			{
				"type": "type4",
				"name": "name4",
				"value": "6",
				"properties": [{
					"type": "MAX12",
					"name": "one12",
					"value": "10012"
				}, {
					"type": "MIN23",
					"name": "five12",
					"value": "532"
				}]
			}
		]
	}]
};

var output = [];
property.data.forEach(function (users) {

	var multirows = {
		id: users.ID,
		name: users.name,
	};

	for (var i = 0; i < users.criteria.length; i++) {
		var criterias = {
			type: users.criteria[i].type,
			name: users.criteria[i].name,
			value: users.criteria[i].value,
		}

		var mat_contacts_rows;
		if (!isEmpty(users.criteria[i].properties)) {
			for (var j = 0; j < users.criteria[i].properties.length; j++) {
				var property = {
					type: users.criteria[i].properties[j].type,
					name: users.criteria[i].properties[j].name,
					value: users.criteria[i].properties[j].value
				};

				mat_contacts_rows = { ...multirows, ...{ criteria: criterias }, ...{ properties: property } };
				output.push(mat_contacts_rows);
			}
		} else {
			var property = [];
			mat_contacts_rows = { ...multirows, ...{ criteria: criterias }, ...{ properties: property } };
			output.push(mat_contacts_rows);
		}
	}
});

console.log(JSON.stringify(output, undefined, 2))


function isEmpty(obj) {
	for (var key in obj) {
		if (obj.hasOwnProperty(key))
			return false;
	}
	return true;
}