在alpine鏡像中添加ansible服務(wù)的方法
使用apk add ansible即可在alpine鏡像中添加ansible服務(wù)。
添加步驟
在alpine中使用ansible需要如下幾步

Dockerfile
在Dockerfile中添加上面的語句:
#update apk for install RUN apk update #install ansible and openssh RUN apk add ansible openssh #init ansible hosts file RUN mkdir -p /etc/ansible RUN echo "localhost" >/etc/ansible/hosts #init rsa ssh key pair RUN ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa #delete cache files RUN rm -rf /var/cache/apk/*
使用鏡像
拉取鏡像
大概103M左右
[root@occluster ~]# docker pull liumiaocn/ansible Using default tag: latest Trying to pull repository docker.io/liumiaocn/ansible ... latest: Pulling from docker.io/liumiaocn/ansible ff3a5c916c92: Already exists 42a81541f983: Pull complete 86602ac17bcb: Pull complete 73cb14e49a3f: Pull complete bdfcad59d746: Pull complete 455ffeaa5bf1: Pull complete dff32643cfa5: Pull complete Digest: sha256:46284f3d3b9e3880f9b65fa6b1fb225b19bc88222badf74aa85936aabc24090f Status: Downloaded newer image for docker.io/liumiaocn/ansible:latest [root@occluster ~]# [root@occluster ~]# docker images |grep ansible docker.io/liumiaocn/ansible latest 8a5cfdf8243f Less than a second ago 103 MB [root@occluster ~]#
使用
進(jìn)行版本確認(rèn)
[root@occluster ~]# docker run -it --name ansible liumiaocn/ansible sh / # ansible --version ansible 2.4.1.0 config file = None configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /usr/bin/ansible python version = 2.7.14 (default, Dec 14 2017, 15:51:29) [GCC 6.4.0] / #
與宿主機(jī)(192.168.163.172)進(jìn)行溝通,事先設(shè)定ssh通路,可以使用ssh-copy-id
/ # ssh-copy-id 192.168.163.172 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host '192.168.163.172 (192.168.163.172)' can't be established. ECDSA key fingerprint is SHA256:uh84Xw56LhiCXb1b0uFbX/CoFhkqHGZjtmLwl3qkTOY. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed expr: warning: '^ERROR: ': using '^' as the first character of a basic regular expression is not portable; it is ignored /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@192.168.163.172's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh '192.168.163.172'" and check to make sure that only the key(s) you wanted were added. / #
ssh通路確認(rèn)
/ # ssh 192.168.163.172 hostname occluster / #
ansible動(dòng)作確認(rèn)
/ # echo "192.168.163.172" >>/etc/ansible/hosts
/ # ansible 192.168.163.172 -m ping
192.168.163.172 | SUCCESS => {
"changed": false,
"failed": false,
"ping": "pong"
}
/ #
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
- Alpine鏡像中telnet轉(zhuǎn)移至busybox-extras
- 基于alpine用dockerfile創(chuàng)建的tomcat鏡像的實(shí)現(xiàn)
- 基于alpine用dockerfile創(chuàng)建的爬蟲Scrapy鏡像的實(shí)現(xiàn)
- Docker從零構(gòu)建php-nginx-alpine鏡像的方法
- ansible批量部署tomcat的方法
- Centos下安裝Ansible的示例代碼
- python ansible服務(wù)及劇本編寫
- ansible作為python模塊庫使用的方法實(shí)例
- linux 自動(dòng)化運(yùn)維工具ansible的使用詳細(xì)教程
- 集群運(yùn)維自動(dòng)化工具ansible之使用playbook安裝zabbix客戶端
相關(guān)文章
解析docker妙用SpringBoot構(gòu)建微服務(wù)實(shí)戰(zhàn)記錄
Spring Boot 是 Spring 開源組織的子項(xiàng)目,是 Spring 組件一站式解決方案,本文通過詳細(xì)案例給大家解析docker妙用SpringBoot構(gòu)建微服務(wù)實(shí)戰(zhàn)記錄,感興趣的朋友跟隨小編一起看看吧2021-11-11
iptables如何限制宿主機(jī)跟Docker IP和端口訪問(安全整改)
本文詳細(xì)介紹了如何通過iptables對(duì)網(wǎng)絡(luò)訪問進(jìn)行限制,包括限制特定IP或網(wǎng)段訪問特定服務(wù),以及在Docker環(huán)境下,如何設(shè)置DOCKER-USER鏈限制IP和端口訪問,確保網(wǎng)絡(luò)安全2024-10-10
Docker中的容器網(wǎng)絡(luò)和通信原理詳解
這篇文章主要介紹了Docker中的容器網(wǎng)絡(luò)和通信原理,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-04-04
本地Docker安裝Postgres 12 + pgadmin的方法 (支持Apple M1)
這篇文章主要介紹了本地Docker安裝Postgres 12 + pgadmin的方法 (支持Apple M1),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03

