ansible的docker_container模块使用

使用docker_container模块创建容器
示例:

---
- hosts: myserverip
remote_user: root # 执行用户
gather_facts: false # 屏蔽系统信息返回
vars:
ansible_python_interpreter: /usr/bin/python3 # 定义ansible使用python3的环境
serial: "100%" # 更新比列,可以是百分比,具体数值
tasks:
- name: docker login # 登陆镜像中心
docker_login:
registry: "harbor.myregister.com"
username: "test"
password: "test"
reauthorize: yes
- name: start containerd
docker_container:
name: servername
image: imagename
hostname: servername
volumes:
- "/etc/localtime:/etc/localtime"
restart_policy: on-failure
network_mode: host # 设置网络模式
log_options: # 设置日志tag 用户elk日志采集筛选
tag: servername
capabilities:
- aLL
env: # 设置环境变量
java_opts: " -Drocketmq.client.name=servername_ip"
cpus: 2.0 # 设置cpu使用
memory: "2G" # 设置内存使用
healthcheck: # 健康检查
test: ["CMD", "curl -f http://localhost:port/actuator/health || exit 1"]
interval: "60s"
timeout: "3s"
start_period: "5s"
retries: 3

更多使用参数,参考官方文档:https://docs.ansible.com/ansible/latest/collections/community/docker/docker_container_module.html#ansible-collections-community-docker-docker-container-module

posted @   蒲公英PGY  阅读(317)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示