我正在使用打包器来制作运输图像,而且我遇到了一个奇怪的问题。 我使用以下行将用户添加到docker组
"sudo groupadd docker",
"sudo usermod -aG docker {{user `service_user`}}",
"sudo usermod -aG docker {{user `config_user`}}",
"newgrp docker",
在执行封隔器模板期间,一切似乎都运行良好;命令echos带有预期值,并创建图像。 Packer将电源关闭vm留在esx上(我使用vsphere)。 我启动它,如果我以服务用户身份登录,我会得到以下结果:
seven10@seven10-sfm:~$ groups
seven10 adm cdrom sudo dip plugdev lxd lpadmin sambashare
seven10@seven10-sfm:~$
但是码头工人组无处可寻!但该小组存在:
seven10@seven10-sfm:~$ cat /etc/group|grep docker
docker:x:999:
如果我重新发出usermod命令,我已正确添加到组中,然后通过重新启动将保留适当的成员资格。 然而,自动执行此操作的关键是避免必须登录并发出usermod命令。 有没有人知道这件事发生了什么以及如何解决它?
编辑:添加了产生相同结果的模板版本
{
"variables": {
"has_automator": "",
"has_hydrator": "",
"has_mongo": "",
"has_rabbit": "",
"service_user": "seven10",
"service_user_pass": "****",
"config_user": "config",
"config_user_pass": "****",
"rabbit_version": "3.6.0-management",
"mongo_version" : "3.4.4",
"docker_user": "****",
"docker_pass": "",
"docker_network_name": "****",
"esx_host": "****",
"vcenter_server": "****",
"vcenter_datacenter": "*****",
"vcenter_datastore": "*****",
"vcenter_username": "*****",
"vcenter_password": "",
"hydra_version": "",
"hydra_name": "",
"vm_disk_size": "100",
"vm_cpu": "4",
"vm_ram": "8000",
"vm_template": "Ubuntu-16.04"
},
"builders": [
{
"type": "vsphere",
"vcenter_server": "{{user `vcenter_server`}}",
"host": "{{user `esx_host`}}",
"datacenter": "{{user `vcenter_datacenter`}}",
"datastore": "{{user `vcenter_datastore`}}",
"username": "{{user `vcenter_username`}}",
"password": "{{user `vcenter_password`}}",
"template": "{{user `vm_template`}}",
"vm_name": "{{user `hydra_name`}}-{{user `hydra_version`}}",
"disk_size": "{{user `vm_disk_size`}}",
"CPUs": "{{user `vm_cpu`}}",
"RAM": "{{user `vm_ram`}}",
"insecure_connection": true,
"ssh_username": "{{user `service_user`}}",
"ssh_password": "{{user `service_user_pass`}}"
}
],
"provisioners": [
{
"type": "shell",
"inline": [
"sleep 10"
]
},
{
"type": "shell",
"execute_command": "echo '{{user `service_user_pass`}}' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'",
"inline": [
"echo 'creating config user account'",
"useradd {{user `config_user`}} -s /bin/bash -m",
"echo {{user `config_user`}}:{{user `config_user_pass`}} | chpasswd"
]
},
{
"type": "shell",
"execute_command": "echo '{{user `service_user_pass`}}' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'",
"inline": [
"echo 'Adding Docker repo to Apt'",
"curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -",
"sudo apt-key fingerprint 0EBFCD88 | grep docker@docker.com || exit 1",
"sudo add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\"",
"echo Updating apt index",
"sudo apt-get update",
"echo 'remove any old vmware tools'",
"sudo apt-get remove -y --purge open-vm-tools",
"echo 'installing required packages'",
"sudo apt-get install -y openssh-server vim curl ufw nfs-common unzip linux-image-extra-$(uname -r) apt-transport-https ca-certificates software-properties-common open-vm-tools-desktop docker-ce openjdk-8-jre-headless",
"echo 'Installing docker",
"sudo groupadd docker",
"sudo usermod -aG docker {{user `service_user`}}",
"sudo usermod -aG docker {{user `config_user`}}",
"newgrp docker",
"echo 'Install docker-compose",
"sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose",
"sudo curl -L https://raw.githubusercontent.com/docker/compose/1.18.0/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose",
"sudo chmod +x /usr/local/bin/docker-compose",
"docker-compose --version",
"echo 'Log in to dockerhub'",
"echo {{user `docker_pass`}} | docker login -u {{user `docker_user`}} --password-stdin",
"echo 'creating docker network'",
"docker network create -d bridge {{user `docker_network_name`}}",
"chown -R {{user `service_user`}}:{{user `service_user`}} /home/{{user `service_user`}}/.docker"
]
}
]
}
vm模板只是我用16.04 ISO编译的机器,安装基础,用户名与service_user相同,然后作为模板导出到vsphere。最终我将移动ISO而不是模板,但这超出了这个问题的范围。
编辑2:
我尝试通过groups
命令之后通过以下任何一项添加newgrp docker
命令的输出
"groups"
"echo $(groups)"
"echo \"$(groups)\"
我得到的只是实际命令(即:vsphere: echo "$(groups)"
)。因此,似乎用户未添加到组中的原因可能是因为它只是回显命令。
这是模板运行时输出的相关部分:
==> vsphere: Provisioning with shell script: /tmp/packer-shell518775104
vsphere: Installing docker
vsphere: sudo groupadd docker
vsphere: sudo usermod -aG docker seven10
vsphere: sudo usermod -aG docker config
vsphere: newgrp docker
vsphere: echo displaying groups
vsphere: echo "$(groups)"
答案 0 :(得分:0)
问题出在此部分:
'
请注意,顶部和底部的echo语句都缺少终止import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="ORDER")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="Order_no")
private int _OrderNo;
@Column(name="Customer_no")
private int _CustomerNo;
public Order() {
}
public Order(int CustomerNo) {
this._CustomerNo = CustomerNo;
}
public int get_OrderNo() {
return _OrderNo;
}
public void set_OrderNo(int OrderNo) {
this._OrderNo = OrderNo;
}
public int get_CustomerNo() {
return _CustomerNo;
}
public void set_CustomerNo(int CustomerNo) {
this._CustomerNo = CustomerNo;
}
@Override
public String toString() {
return "Order [_OrderNo=" + _OrderNo + ", _CustomerNo=" + _CustomerNo + "]";
}
}
。因此,两者之间的所有内容都被视为初始回声的一部分。
检查你的字符串终止符,小孩。