简体   繁体   中英

docker-compose.yml: Error while specifying a tmpfs volume

For following docker run command,

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

I would like to run it via docker-compose up

Here is 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:

I am getting the following error when i run 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

How can I resolve it?

You're using docker-compose file version 3, and you need version 3.6 if you want to use -type: tmpfs specifying target.

Just try replacing version: "3" by version: "3.6"

More information in: Docker compose info to use tmpfs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM