自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

使用ansible-bender構(gòu)建容器鏡像

系統(tǒng)
容器和 Ansible 可以很好地融合在一起:從管理和編排到供應(yīng)和構(gòu)建。在本文中,我們將重點(diǎn)介紹構(gòu)建部分。

[[280773]]

了解如何使用 Ansible 在容器中執(zhí)行命令。

容器和 Ansible 可以很好地融合在一起:從管理和編排到供應(yīng)和構(gòu)建。在本文中,我們將重點(diǎn)介紹構(gòu)建部分。

如果你熟悉 Ansible,就會(huì)知道你可以編寫一系列任務(wù),ansible-playbook 命令將為你執(zhí)行這些任務(wù)。你知道嗎,如果你編寫 Dockerfile 并運(yùn)行 podman build,你還可以在容器環(huán)境中執(zhí)行此類命令,并獲得相同​​的結(jié)果。

這是一個(gè)例子:

  1. - name: Serve our file using httpd
  2. hosts: all
  3. tasks:
  4. - name: Install httpd
  5. package:
  6. name: httpd
  7. state: installed
  8. - name: Copy our file to httpds webroot
  9. copy:
  10. src: our-file.txt
  11. dest: /var/www/html/

你可以在 Web 服務(wù)器本地或容器中執(zhí)行這個(gè)劇本,并且只要你記得先創(chuàng)建 our-file.txt,它就可以工作。

但是這里缺少了一些東西。你需要啟動(dòng)(并配置)httpd 以便提供文件。這是容器構(gòu)建和基礎(chǔ)架構(gòu)供應(yīng)之間的區(qū)別:構(gòu)建鏡像時(shí),你只需準(zhǔn)備內(nèi)容;而運(yùn)行容器是另一項(xiàng)任務(wù)。另一方面,你可以將元數(shù)據(jù)附加到容器鏡像,它會(huì)默認(rèn)運(yùn)行命令。

這有個(gè)工具可以幫助。試試看 ansible-bender 怎么樣?

  1. $ ansible-bender build the-playbook.yaml fedora:30 our-httpd

該腳本使用 ansible-bender 對(duì) Fedora 30 容器鏡像執(zhí)行該劇本,并將生成的容器鏡像命名為 our-httpd。

但是,當(dāng)你運(yùn)行該容器時(shí),它不會(huì)啟動(dòng) httpd,因?yàn)樗恢廊绾尾僮鳌D憧梢酝ㄟ^(guò)向該劇本添加一些元數(shù)據(jù)來(lái)解決此問(wèn)題:

  1. - name: Serve our file using httpd
  2. hosts: all
  3. vars:
  4. ansible_bender:
  5. base_image: fedora:30
  6. target_image:
  7. name: our-httpd
  8. cmd: httpd -DFOREGROUND
  9. tasks:
  10. - name: Install httpd
  11. package:
  12. name: httpd
  13. state: installed
  14. - name: Listen on all network interfaces.
  15. lineinfile:
  16. path: /etc/httpd/conf/httpd.conf
  17. regexp: '^Listen '
  18. line: Listen 0.0.0.0:80
  19. - name: Copy our file to httpds webroot
  20. copy:
  21. src: our-file.txt
  22. dest: /var/www/html

現(xiàn)在你可以構(gòu)建鏡像(從這里開(kāi)始,請(qǐng)以 root 用戶身份運(yùn)行所有命令。目前,Buildah 和 Podman 不會(huì)為無(wú) root 容器創(chuàng)建專用網(wǎng)絡(luò)):

  1. # ansible-bender build the-playbook.yaml
  2. PLAY [Serve our file using httpd] ****************************************************
  3. TASK [Gathering Facts] ***************************************************************
  4. ok: [our-httpd-20191004-131941266141-cont]
  5.  
  6. TASK [Install httpd] *****************************************************************
  7. loaded from cache: 'f053578ed2d47581307e9ba3f64f4b4da945579a082c6f99bd797635e62befd0'
  8. skipping: [our-httpd-20191004-131941266141-cont]
  9.  
  10. TASK [Listen on all network interfaces.] *********************************************
  11. changed: [our-httpd-20191004-131941266141-cont]
  12.  
  13. TASK [Copy our file to httpds webroot] **********************************************
  14. changed: [our-httpd-20191004-131941266141-cont]
  15.  
  16. PLAY RECAP ***************************************************************************
  17. our-httpd-20191004-131941266141-cont : ok=3 changed=2 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
  18.  
  19. Getting image source signatures
  20. Copying blob sha256:4650c04b851c62897e9c02c6041a0e3127f8253fafa3a09642552a8e77c044c8
  21. Copying blob sha256:87b740bba596291af8e9d6d91e30a01d5eba9dd815b55895b8705a2acc3a825e
  22. Copying blob sha256:82c21252bd87532e93e77498e3767ac2617aa9e578e32e4de09e87156b9189a0
  23. Copying config sha256:44c6dc6dda1afe28892400c825de1c987c4641fd44fa5919a44cf0a94f58949f
  24. Writing manifest to image destination
  25. Storing signatures
  26. 44c6dc6dda1afe28892400c825de1c987c4641fd44fa5919a44cf0a94f58949f
  27. Image 'our-httpd' was built successfully \o/

鏡像構(gòu)建完畢,可以運(yùn)行容器了:

  1. # podman run our-httpd
  2. AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.88.2.106. Set the 'ServerName' directive globally to suppress this message

是否提供文件了?首先,找出你容器的 IP:

  1. # podman inspect -f '{{ .NetworkSettings.IPAddress }}' 7418570ba5a0
  2. 10.88.2.106

你現(xiàn)在可以檢查了:

  1. $ curl http://10.88.2.106/our-file.txt
  2. Ansible is

你文件內(nèi)容是什么?

這只是使用 Ansible 構(gòu)建容器鏡像的介紹。如果你想了解有關(guān) ansible-bender 可以做什么的更多信息,請(qǐng)查看它的 GitHub 頁(yè)面。構(gòu)建快樂(lè)! 

 

責(zé)任編輯:龐桂玉 來(lái)源: Linux中國(guó)
相關(guān)推薦

2019-09-10 13:34:30

Linux操作系統(tǒng)軟件

2021-05-17 12:54:04

AnsiblePodman開(kāi)源

2023-11-03 13:20:13

Kubernetes

2020-01-02 10:44:22

運(yùn)維架構(gòu)技術(shù)

2019-05-22 15:36:22

Linux容器鏡像

2023-10-30 11:01:37

Buildpack云原生

2021-08-30 06:27:21

工具容器Docker

2017-03-24 09:24:21

HarborDocker鏡像倉(cāng)庫(kù)

2024-02-20 08:08:43

2023-09-14 09:31:21

Docker容器

2023-11-28 13:17:21

mkosiRHELRHEL UBI

2021-08-23 08:30:30

Docker BuildKit 架構(gòu)

2016-10-17 13:33:26

原子主機(jī)AnsibleCockpit

2020-10-29 10:17:24

AnsibleKubernetes容器編排自動(dòng)化

2023-11-26 00:52:12

Docker鏡像容器

2017-06-13 14:43:27

容器數(shù)據(jù)鏡像系統(tǒng)

2021-09-08 19:46:11

容器鏡像Linux

2021-01-05 08:39:51

容器前端流水線

2021-05-13 09:07:03

容器云環(huán)境鏡像

2019-12-16 12:11:53

Docker容器Kubernetes
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)