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
-d
is an option of subcommandup
.if you run
docker compose up --help
you will have more information.To solve the problem run
docker compose up -d
We were using a legacy version of Docker for compatibility purposes; in the older versions it’s
docker-compose
notdocker compose
. Changing it to be hyphenated resolved this error.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:The accepted answer telling me to run exactly what I ran was pretty confusing. I finally worked out that:
docker-compose
is a separate package fromdocker
, at least on Arch Linux, and likely elsewhere, andIf
docker-compose
isn’t installed, Docker thinks this makes sense:I think it wold be infinitely more sensible to respond with:
Which is what it says if you don’t use
-d
while not havingdocker-compose
installed. I’ve now installeddocker-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 havedocker
but notdocker-compose
.