compose: docker compose - unknown shorthand flag: f
- This is a bug report
- This is a feature request
- I searched existing issues before opening this one
Expected behavior
docker compose -f docker-compose.dev.yml build
should build a project using docker-compose.dev.yml
Actual behavior
I get the error “unknown shorthand flag: ‘f’ in -f”
Steps to reproduce the behavior
Output of docker version
:
Client: Docker Engine - Community
Version: 20.10.11
API version: 1.41
Go version: go1.16.9
Git commit: dea9396
Built: Thu Nov 18 00:35:56 2021
OS/Arch: linux/arm64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.11
API version: 1.41 (minimum version 1.12)
Go version: go1.16.9
Git commit: 847da18
Built: Thu Nov 18 00:34:31 2021
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Output of docker info
:
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.6.3-docker)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.11
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc version: v1.0.2-0-g52b36a2
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 5.4.0-90-generic
Operating System: Ubuntu 20.04.3 LTS
OSType: linux
Architecture: aarch64
CPUs: 1
Total Memory: 974.8MiB
Name: primary
ID: HLIN:2GYA:RRNJ:LLP7:3FFW:CUF3:LBTA:N2SX:KSST:U3EX:3NHL:TG46
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Additional environment details (AWS, VirtualBox, physical, etc.)
Docker is running on MacOS Monterrey in a Virtual Maschine (Ubuntu 20.10, Canonical Multipass)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 10
- Comments: 25 (6 by maintainers)
if it helps anyone else, I thought that I had run into this issue with the following command
however, after moving the
up
to the end:it started working correctly.
just in case anyone else thinks they may have run into the same problem
Solution is
apt install docker-compose
and change your command to usedocker-compose
.Have the same problem. I suppose it is not fixed yet. Docker seems not to understand when you are running docker commands vs docker compose commands when using the -f flag and sudo in Ubuntu. Some examples.
If I run
docker compose -f some/docker-compose.yml up -d
as suggested, I get a permission denied error. If I use sudo, docker thinks it’s a docker command, not a docker compose command.Commands runned Option 1
sudo docker compose up -f docker-compose.dev.yml
Result 1Option 2
sudo docker compose -f docker-compose.dev.yml up
Result 2If anyone has a solution it would be very welcomed, otherwise I will have to switch to v1. Thanks!
Solved
Had to move the docker-compose script to be usable by root. Solution
This is the correct answer. Do note the “–file” / “-f” flag is shown in
docker-compose --help
, and notdocker-compose up --help
, so it has to be before the up.@MMendozaEscalona so you’re using a old version of Compose v1 (in python), and Compose v1 is end-of-life, please install the Compose v2, if you’re on linux follow this steps and if you’re using Docker Desktop verify you didn’t uncheck the
Use Docker Compose V2
checkbox in Preferences view Maybe that the same for you @digitaltim-de?Not sure if this will be helpful for anyone, but I ran across this issue when setting a cron executing
docker compose
commands.My issue was that I had installed docker compose with a specific user, so running
docker compose
from the cron shell script (which default was using the root user) was interpreting it as thedocker
command itself (which doesn’t have an-f
flag).To correct this, I added
sudo -u <user>
in front of thedocker compose ...
, which ran the command from the user which had installed it.@DrEsteban
-f
is unfortunately also used by some subcommand as shorthand for--format
, so allowing use after command would create some more issues.@michaelpeterlee @tangopium Can you share the result of
docker compose version
This looks to be an issue with compose v2 (likely apt install installed the old v1 version)
let me transfer this issue to the compose issue tracker