如何使用Packer Salt配置器创建docker镜像?
这是我的packer.json
文件。我将在下面内联评论
{
"builders": [
{
"type": "docker",
"image": "enonic/docker-salt-masterless-ubuntu",
"export_path": "cassandra.tar" // Not sure what this is doing?
}
],
"provisioners": [
{
"type": "file",
"source": "/srv/salt/cassandra", // This is where the cassandra directory is on my host machine which is ubuntu
"destination": "/srv/salt/cassandra" // This is where I expect the cassandra directory on my host machine gets copied to inside a docker container
},
{
"type": "salt-masterless",
"local_state_tree": "/srv/salt/cassandra",
"custom_state": "/srv/salt/cassandra/init.sls",
"disable_sudo": true
}
]
}
sudo docker build packer.json
我收到以下错误
Build 'docker' errored: Failed to upload to '/srv/salt/cassandra' in container: Error response from daemon: lstat /var/lib/docker/aufs/mnt/0c6a422400a073624a66b00580a6b9e5551e82a06495c46b1f840b38ca55699d/srv/salt: no such file or directory
. exit status 1.
==> Some builds didn't complete successfully and had errors:
--> docker: Failed to upload to '/srv/salt/cassandra' in container: Error response from daemon: lstat /var/lib/docker/aufs/mnt/0c6a422400a073624a66b00580a6b9e5551e82a06495c46b1f840b38ca55699d/srv/salt: no such file or directory
如果我能得到一个关于如何使用主机上的salt状态文件并使用packer构建docker镜像的简单工作示例,那将是很棒的。我的cassandra状态文件与https://github.com/salt-formulas/salt-formula-cassandra
相同我的top.sls
文件看起来像这样
base:
'client*-es-*':
- roles-elasticsearch
'client*-cassandra-*':
- roles-cassandra
'P@os:(Debian|Ubuntu) and P@roles:(elasticsearch|cassandra)':
- match: compound
- deb-common
'roles:elasticsearch':
- match: grain
- disk-raid0-3volumes
- disk-elasticsearch
- elasticsearch
- elasticsearch.cerebro
'roles:cassandra':
- match: grain
- disk-raid0-3volumes
- disk-cassandra
- cassandra
我只想为cassandra构建一个docker容器图像,而不是为top.sls
中的所有内容构建一个docker容器图像。那我该怎么做?
答案 0 :(得分:2)
我将您的示例调整为更简单,只需安装Apache 2。
shell
供应商仅仅是因为我不知道盐而且不会花时间去做apt-get update
。
首先,基本映像已经安装了salt,因此请使用skip_bootstrap
。您不应该将状态目录上传到guest虚拟机(Docker容器),因为这是自动完成的,所有这些都在文档Packer - Salt Masterless中。 local_state_tree
应指向盐状态树的基础。在你的情况下/srv/salt
。
一个工作示例:
<强>树强>
.
├── salt
│ ├── apache
│ │ └── init.sls
│ └── top.sls
└── template.json
<强> Template.json 强>
{
"builders": [
{
"type": "docker",
"image": "enonic/docker-salt-masterless-ubuntu",
"export_path": "apache2.tar"
}
],
"provisioners": [
{
"type": "shell",
"inline": [
"apt-get update"
]
},
{
"type": "salt-masterless",
"local_state_tree": "salt",
"skip_bootstrap": true,
"disable_sudo": true
}
]
}
<强> top.sls 强>
base:
'*':
- apache
<强>阿帕奇/ init.sls 强>
apache2:
pkg.installed: []
service.running:
- require:
- pkg: apache2
答案 1 :(得分:1)
您需要将NextParticle
更改为local_state_path
。