docker-compose.yml:指定tmpfs卷时出错

时间:2018-04-15 19:29:13

标签: docker docker-compose

对于以下泊坞窗运行命令,

docker run --rm -itd --privileged --cap-add=SYS_PTRACE --cap-add=SYS_ADMIN -v /dev/shm --tmpfs /dev/shm:rw,nosuid,nodev,exec centos:7

我想通过docker-compose up

运行它

这是docker-compose.yml

version: "3"
services:
  centos-testing:
    image: centos:7
    privileged: true
    tty: true
    stdin_open: true
    ulimits:
      nproc: 655353
      nofile:
        soft: 20000
        hard: 40000
    cap_add:
        - SYS_PTRACE
        - SYS_ADMIN
    volumes:
      - type: tmpfs
        source: /dev/shm
        target: /dev/shm:rw,nosuid,nodev,exec
    networks:
      - testnet
    deploy:
      mode: replicated
      replicas: 1
      resources:
        limits:
          cpus: "2"
          memory: 50M
      restart_policy:
        condition: on-failure

networks:
  testnet:

运行docker-compose up

时出现以下错误
ERROR: The Compose file './docker-compose.yml' is invalid because:
services.centos-testing.volumes contains an invalid type, it should be a string

我该如何解决?

1 个答案:

答案 0 :(得分:1)

您正在使用docker-compose文件版本3,如果您想使用-type: tmpfs指定目标,则需要3.6版。

尝试将version: "3"替换为version: "3.6"

更多信息: Docker compose info to use tmpfs