"docker context create" requires exactly 1 argument

hi all,
I was trying to create a new context to work with AWS so from everything I researched, it looks like the following command should work:
docker context create ecs myeccontext

when I run the above command, I get the following error.
“docker context create” requires exactly 1 argument.
See ‘docker context create --help’.
Usage: docker context create [OPTIONS] CONTEXT
Create a context

I’m running docker on MacOS Monterey 12.5.1
docker --version
Docker version 20.10.17, build 100c70180f

current context list:
docker context ls
NAME DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR
default * Current DOCKER_HOST based configuration unix:///var/run/docker.sock swarm
desktop-linux unix:///Users/username/.docker/run/docker.sock

I can log into AWS as the below command shows I can log in:
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin ***************90.dkr.ecr.us-east-1.amazonaws.com
Login Succeeded

So what am I missing?

thank you.

Why would a login to ECR indicate that access to an ECS Cluster would work?
Did you follow the prerequisites from Deploying Docker containers on ECS | Docker Documentation?

It works on my Mac, same versions. Are you sure you didn’t have a typo in your command? Is the command that you shared here the exact same command that you ran in the terminal or did you typed the command again here without a typo?

For example this works:

docker context create ecs myeccontext

and this gives me the same error as you had:

docker context create eccs myeccontext

since ecs is a valid command but eccs is not so docker context create expects a context name where eccs is and myeccontext would be an other argument of create, but it has only one. If you write the right command, then ecs is a subcommand of create and myeccontext is an argument of ecs and not create.

hi,
Thanks guys, I will look at both of your suggestions.

@xender2022 I’m experiencing the same issue:

Docker Desktop About:
Version: 4.12.0 (85629)
Engine: 20.10.17
Compose: 1.29.2

OS: MacOs Monterey 12.6 (21G115), Apple M1 Chip

docker context ls
NAME            DESCRIPTION                               DOCKER ENDPOINT                                    KUBERNETES ENDPOINT   ORCHESTRATOR
default *       Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                                              swarm
desktop-linux                                             unix:///Users/username/.docker/run/docker.sock
ecs                                                       unix:///var/run/docker.sock                                              swarm
test                                                      unix:///var/run/docker.sock                                              swarm
docker context create ecs myecscontext
"docker context create" requires exactly 1 argument.
See 'docker context create --help'.

Usage:  docker context create [OPTIONS] CONTEXT

Create a context
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin ******.dkr.ecr.us-west-2.amazonaws.com
Login Succeeded

hi Jed,

I haven’t figured it out yet. I am still working on it.

Just solved this by installing compose-cli as documented here: Deploying Docker containers on ECS | Docker Documentation

1 Like

I can’t reproduce the issue, so unfortunately I don’t know who I could help you.

The only thing I noticed in your configuration is that you use Docker desktop, but when you listed your Docker contexts, it looks like the activate context is not Docker Desktop, but Docker CE.

On Mac

curl -L https://raw.githubusercontent.com/docker/compose-cli/main/scripts/install/install_linux.sh | sh

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5982  100  5982    0     0  17610      0 --:--:-- --:--:-- --:--:-- 18182
Running checks...
Error: Script not needed on macOS, please install Docker Desktop Edge: https://www.docker.com/products/docker-desktop

Docker Compose is part of Docker Desktop, but I doubt that it will help you to create the context without using Docker Compose.

Can you explain why it helped? How could you crete the context after installing Docker Compose?

I’m not using Docker Desktop. My environment is a Linux machine (Ubuntu 22.04) with docker engine installed. Just posted that installing compose-cli solved my issue.

@tfgcampos The Docker Desktop part of my message was a reply to @jedmittendevo, not for you. Sorry for the confusion.

Yes, and this is what I am curious about :slight_smile: Does docker context create ecs contextname worked for you just because you installed Docker Compose or you had a different problem and you used only Docker Compose not docker context create?

I needed to create an ECS context to run a workload in AWS, and original docker command don’t have support to ECS. Now that I have compose-cli and docker engine installed, I can simulated both scenarios running /usr/bin/docker (docker engine’s one) or /usr/local/bin/docker (compose-cli’s one):

running /usr/bin/docker

~$ /usr/bin/docker context create ecs test
"docker context create" requires exactly 1 argument.
See 'docker context create --help'.

Usage:  docker context create [OPTIONS] CONTEXT

Create a context

running /usr/local/bin/docker

~$ /usr/local/bin/docker context create ecs test
? Create a Docker context using: An existing AWS profile
? Select AWS Profile default
Successfully created ecs context "test"

Probably this is the issue @xender2022 is facing. There is probably two docker executables, and PATH defines the search path priority for execution. It’s worth trying to execute ‘whereis docker’ to check if other executables exists. Below is mine:

~$ whereis docker
docker: /usr/bin/docker /etc/docker /usr/local/bin/docker /usr/libexec/docker /usr/share/man/man1/docker.1.gz

And my PATH definition (/usr/local are executed first):

~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
1 Like

I just completed the following:

  1. remove docker completely
  2. remove aws cli completely
  3. rebooted mac
    ======================
  4. installed docker desktop which includes docker compose by default on mac
  5. installed aws cli v2

whereis docker
docker: /opt/homebrew/bin/docker /opt/homebrew/share/man/man1/docker.1, looks like my docker is executed from /opt/homebrew/bin

I also see these:
lrwxr-xr-x 1 root wheel 54 Oct 18 15:01 docker → /Applications/Docker.app/Contents/Resources/bin/docker
lrwxr-xr-x 1 root wheel 62 Jul 1 16:32 docker-compose → /Applications/Docker.app/Contents/Resources/bin/docker-compose
lrwxr-xr-x 1 root wheel 80 Jul 1 16:32 docker-compose-v1 → /Applications/Docker.app/Contents/Resources/bin/docker-compose-v1/docker-compose
lrwxr-xr-x 1 root wheel 73 Jul 1 16:32 docker-credential-desktop → /Applications/Docker.app/Contents/Resources/bin/docker-credential-desktop
lrwxr-xr-x 1 root wheel 75 Jul 1 16:32 docker-credential-ecr-login → /Applications/Docker.app/Contents/Resources/bin/docker-credential-ecr-login
lrwxr-xr-x 1 root wheel 77 Jul 1 16:32 docker-credential-osxkeychain → /Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain

Do you think I need to delete these from /usr/local/bin and just use the /opt/homebrew/bin version?

docker version
Client: Docker Engine - Community
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.18.3
 Git commit:        100c70180f
 Built:             Mon Jun  6 21:36:39 2022
 OS/Arch:           darwin/arm64
 Context:           default
 Experimental:      true

This solved my immediate issue! Thanks @tfgcampos !

/usr/local/bin/docker context create ecs ecscontext
? Create a Docker context using: An existing AWS profile
? Select AWS Profile default
Successfully created ecs context "ecscontext"

Now I need to get only one instance of Docker and AWS cli installed. Excellent help.

1 Like

Run: brew uninstall docker

1 Like

I realized I was completely wrong when I wrote this:

I ignored the fact that you just wrote that you used macOS so it could not have been Docker CE…

Thank you for sharing your solution. Strange, because the installer of Docker Compose should not install an other docker binary and it indeed does. I can confirm it know and I could also reproduce the issue. I guess it worked for me because I tried on my mac, but when I ran a virtual machine on macOS using multipass, the pre-installed docker cli did not understand ecs, but the other one did.

It is strange, because the two docker binary gives me the same information when I run docker version, but they are different and they have different size. So something is wrong here, but I am glad that you finally found the cause.

1 Like

Looks like i had the same issue with jed. As soon as I specifically used /usr/local/bin/docker, the context command finally worked.
Also removed homebrew installed docker so that the default docker is ran from /usr/local/bin.

Thank you all.

Same issue with me, I solved it using sudo,

$ sudo docker context create ecs mycontext

image

Yep… it works!

Env:
Windows 10 Version 20H2(Compilation SO 19042.1526)
Docker Desktop v4.16.3
WSL 2.0
Ubuntu 20.04