如何使用Packer Salt Provisioner创建Docker Images?
这是我的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
,如果我能获得一个简单的工作示例,那就是如何使用盐状态机器中的盐状态文件并使用Packer构建Docker Image,那就太好了。我的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
中的所有内容。那我该怎么做?
我调整了您的示例更简单,只需安装apache 2。
shell
供应商只是因为我不知道盐,而din不花任何时间在howto做apt-get update
上。
首先,基本图像已经安装了盐,因此请使用skip_bootstrap
。您不应该将状态目录上传到来宾(Docker容器),因为这是自动完成的,所有这些都是在文档包装器中 - 无盐。local_state_tree
应指向盐状态树的底部。/srv/salt
在您的情况下。
一个工作示例:
tree
.
├── 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
apache/init.sls
apache2:
pkg.installed: []
service.running:
- require:
- pkg: apache2
您需要将local_state_path
更改为/srv/salt
。