9

I am working with a docker compose. when a trying to run docker compose in background, but it shows error unknown shorthand flag: 'd' in -d

I am tried in this way

docker compose -d up

docker-compose.yml

version: '3'

networks:
  loki:

services:
  loki:
    image: grafana/loki:2.5.0
    # volumes:
    #   - ./loki:/loki
    ports:
      - 3100:3100
    networks:
      - loki
  
  promtail:
    image: grafana/promtail
    volumes:
      - ./promtail:/etc/promtail
      - /var/log/nginx/:/var/log/nginx/
    command: -config.file=/etc/promtail/promtail-config.yml
    ports:
      - 9080:9080
    networks:
      - loki
  
  grafana:
    image: grafana/grafana
    ports:
      - 3000:3000
    networks:
      - loki
    
  
Jan Garaj
  • 25,598
  • 3
  • 38
  • 59
Amjed saleel
  • 348
  • 1
  • 3
  • 15
  • 1
    Does this answer your question? [docker-compose for Detached mode](https://stackoverflow.com/questions/38086453/docker-compose-for-detached-mode) – decorator-factory May 31 '22 at 11:29

3 Answers3

12

-d is an option of subcommand up. if you run docker compose up --help you will have more information.

To solve the problem run docker compose up -d

Lucien Makutano
  • 171
  • 1
  • 7
8

The accepted answer is the right answer for the question asker, and anyone else putting the -d in the wrong place. But this is the top hit for the error message, and I'm sure I'm not the only one getting this error after running:

docker-compose up -d

The accepted answer telling me to run exactly what I ran was pretty confusing. I finally worked out that:

  1. docker-compose is a separate package from docker, at least on Arch Linux, and likely elsewhere, and

  2. If docker-compose isn't installed, Docker thinks this makes sense:

    $ docker compose up -d
    unknown shorthand flag: 'd' in -d
    

I think it wold be infinitely more sensible to respond with:

docker: 'compose' is not a docker command.

Which is what it says if you don't use -d while not having docker-compose installed. I've now installed docker-compose and things are working, but I thought it was worth the time to hopefully save someone else some trouble if they end up here because they have docker but not docker-compose.

Darshan Rivka Whittle
  • 32,989
  • 7
  • 91
  • 109
  • Thank you, this worked for me, if you are on Arch a simple `sudo pacman -S docker-compose` fixes the issue – Netsu Apr 05 '23 at 15:44
6

We were using a legacy version of Docker for compatibility purposes; in the older versions it's docker-compose not docker compose. Changing it to be hyphenated resolved this error.

Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195