加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

docker-compose,在容器启动后运行脚本?

发布时间:2020-12-16 03:35:58 所属栏目:安全 来源:网络整理
导读:我有一个服务,我通过牧场主通过docker-compose提出.我遇到的问题是我需要在部署容器后设置密码. 牧场主秘密工作的方式是,我设置我的秘密,牧场主将在我的容器上装载一个包含我的秘密的文件.我希望能够执行一个脚本来获取该秘密,并将其设置为我的配置文件中的

我有一个服务,我通过牧场主通过docker-compose提出.我遇到的问题是我需要在部署容器后设置密码.

牧场主秘密工作的方式是,我设置我的秘密,牧场主将在我的容器上装载一个包含我的秘密的文件.我希望能够执行一个脚本来获取该秘密,并将其设置为我的配置文件中的密码.

我不相信我有办法通过Dockerfile获取秘密,因为我不想让秘密存在于git中,所以我只是想通过docker-compose来做这件事.

有谁知道这是否可能?

最佳答案
docker-compose指定如何启动容器,而不是如何修改现有的运行容器.

Rancher documentation提到,对于秘密的默认使用,您可以在docker-compose.yml的secrets数组中按名称引用秘密.

The target filename will be the same name as the name of the secret.
By default,the target filename will be created as User ID and Group ID 0,and File Mode of 0444.
Setting external to true in the secrets part will make sure it knows the secret has already been created.

Example of a basic docker-compose.yml:

version: '2'
services:
  web:
    image: sdelements/lets-chat
    stdin_open: true
    secrets:
    - name-of-secret
    labels:
      io.rancher.container.pull_image: always
secrets:
  name-of-secret:
    external: true

如“How to Update a Single Running docker-compose Container”中所示,更新容器将涉及“构建,终止和向上”序列.

docker-compose up -d --no-deps --build 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读