如何编写要在docker compose中执行的命令?

发布于 2025-01-14 17:28:21 字数 848 浏览 2 评论 0原文

我对 docker 和 docker compose 有点陌生。我使用的是 20.10.12 版本的 docker 和 2.9.0 版本的 portainer。我的目标是为elasticSearch做docker compose,将其部署在portainer中,但我遇到一个问题,即给定的内存不够。查看其他问题后,我发现我可以执行以下 bash 命令来为虚拟机内存分配更大的限制

sysctl -w vm.max_map_count=262144

所以我的 .yml 是这样的:

version: "3.8"

services:
  command: >
      bash -c ' sysctl -w vm.max_map_count=262144'
  master1:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.0.0
    environment:                  
      node.name: "master1"
    ulimits:
        memlock:
          soft: -1
          hard: -1        
    deploy:
      endpoint_mode: dnsrr         
      mode: "replicated"
      replicas: 1
      resources:
        limits:
          memory: 4G

问题是,当我尝试部署此组合时,它显示“services.command”必须是一个映射”。

我认为当缩进不正确时就会出现问题,但我认为在我的情况下缩进是正确的。

I am kind of new to docker and docker compose. I am using 20.10.12 version of docker and 2.9.0 of portainer. My aim is to do the docker compose for elasticSearch to deploy it in portainer but I get a problem that the memory given is not enough. After looking through other questions I found that I could execute the following bash command to assign a bigger limit to the VM memory

sysctl -w vm.max_map_count=262144

So my .yml is like this:

version: "3.8"

services:
  command: >
      bash -c ' sysctl -w vm.max_map_count=262144'
  master1:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.0.0
    environment:                  
      node.name: "master1"
    ulimits:
        memlock:
          soft: -1
          hard: -1        
    deploy:
      endpoint_mode: dnsrr         
      mode: "replicated"
      replicas: 1
      resources:
        limits:
          memory: 4G

The problem is that when I try to deploy this compose, it says "services.command must be a mapping".

I think that problem is raised when then indentation is not correct but I think in my case is indented correctly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心在旅行 2025-01-21 17:28:21

vm.max_map_count 必须在主机上设置,而不是在 docker 容器中设置。
按照 这个官方文档。

vm.max_map_count must be set on the host, and not in the docker container.
Set it as described in this official doc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文