skip to Main Content

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
    
  

3

Answers


  1. -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

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search