我想从Jenkins作业在远程主机上运行两个容器。我有ssh访问权限,但我不想使用ssh。
目前的工作原理如下:
ssh -T <HOST> docker login -u testuser -p testpassword registry:5000
ssh -T <HOST> docker pull registry:5000/db:${VERSION}
ssh -T <HOST> docker pull registry:5000/app:${VERSION}
如果没有ssh -T
我该怎么办?
答案 0 :(得分:3)
在Jenkins上安装Docker客户端,然后使用TLS密钥设置Docker服务器和客户端。这里是快速浏览设置自签名CA +密钥的命令:
# work in a secure folder mkdir docker-ca && chmod 700 docker-ca && cd docker-ca # generate a key pair for the CA openssl genrsa -aes256 -out ca-key.pem 2048 # setup CA certificate openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem # make sure to set CN
# generate a new host key pair openssl genrsa -out myserver-key.pem 2048 # generate certificate signing request (CSR) openssl req -subj "/CN=myserver" -new -key myserver-key.pem -out myserver.csr # setup extfile for ip's to allow echo "subjectAltName = IP:$myserver_ip, IP:127.0.0.1" >extfile.cnf # sign the key by the CA openssl x509 -req -days 365 -in myserver.csr -CA ca.pem -CAkey ca-key.pem \ -CAcreateserial -out myserver-cert.pem -extfile extfile.cnf # test server by updating service: /usr/bin/docker daemon -H fd:// -H tcp://0.0.0.0:2376 --tlsverify \ --tlscacert=/etc/docker/ca.pem --tlscert=/etc/docker/myserver-cert.pem \ --tlskey=/etc/docker/myserver-key.pem
您希望使用上面的TLS选项更新服务器启动脚本,这会因平台而异,但systemd文件将从/lib/systemd/system/docker.service
复制到/etc/systemd/system/docker.service
,然后进行编辑,然后已加载sudo systemctl daemon-reload && sudo systemctl restart docker
。
# create a client key pair openssl genrsa -out client-key.pem 2048 # generate csr for client key openssl req -subj '/CN=client' -new -key client-key.pem -out client.csr # configure request to support client echo extendedKeyUsage = clientAuth >extfile.cnf # sign the client key with the CA openssl x509 -req -days 365 -in client.csr -CA ca.pem -CAkey ca-key.pem \ -CAcreateserial -out client-cert.pem -extfile extfile.cnf # test client with docker --tlsverify \ --tlscacert=ca.pem --tlscert=client-cert.pem --tlskey=client-key.pem \ -H=tcp://127.0.0.1:2376 info`
在$HOME/.docker
中,您可以添加:ca.pem,key.pem和cert.pem。然后export DOCKER_TLS_VERIFY=1
和export DOCKER_HOST=your_docker_server
作为登录脚本(.bashrc)的一部分。
答案 1 :(得分:0)
您可以将Docker客户端安装到Jenkins Box中,并使用它来更新容器。
答案 2 :(得分:-1)
对于此任务,我使用了docker远程API。