Accessing organization resources through the docker-cloud CLI - possible?

I have an organization that has multiple users being part of this organization.

When I used my private docker account I could access the resources such as stacks, etc. through the docker-cloud CLI.

I’m using MacOS with docker-cloud CLI installed using brew.

How am I supposed to address any resources associated with the organization? I can only see my personal stacks and resources when I use the CLI. Is there a way to log in as the organization or in some other way specify which organization to work with?

The docker-cloud login argument doesn’t really provide much options.

Thanks!

Hi @andershansson,
Sorry for the delay, I missed your post. :frowning: We recently updated the rest api docs with information about Namespaced endpoints in the API:
https://docs.docker.com/apidocs/docker-cloud/#namespaced-endpoints

The TL;DR: version is that you can pass an optional namespace in the API calls to access organization resources. If you don’t specify a namespace, the API assumes you mean the namespace of the authenticated user.

Thank you for the reply!

I’m still a bit confused how this translates beyond the HTTP API calls (where you are able to specify the URL).

When I use the CLI there is no way to specify the namespace - or am I missing something here?

We’re in a situation where we try to automate part of the deployment process and a part of that is to be able to push new versions of the stack definition file from the command line. I would rather not have to dive into the HTTP REST API calls just to do that if not absolutely necessary. Also it would be nice to be able to use the other CLI commands towards an organisation (namespace).

Thanks in advance! And also thanks for an awesome service - Docker Cloud has really made my life soo much easier.

1 Like

Hi @andershansson!

You can do it -> https://github.com/docker/dockercloud-cli#namespace
Either you set the environment variable to work with your organisation or you prefix the env var before every CLI command, whatever works best for your use case.

Basically (maybe this info is useful to your automation), what CLI does is to add the namespace in the resource URI that you are going to work with. For example, the list URL to work with stacks is

/api/app/v1/(namespace/)stack/

Where the namespace is optional. If you do not specify the namespace, by default it will take the namespace of the user that logs in.

You can play with it with curl:
curl -u username:password https://cloud.docker.com/api/app/v1/stack/ will work in “username”'s namespace, but if you specify it, like in curl -u username:password https://cloud.docker.com/api/app/v1/myorg/stack/ will work in “myorg” namespace.
https://cloud.docker.com/api/app/v1/username/stack/ will work too, in username’s namespace. CLI adds this variable when you specify DOCKERCLOUD_NAMESPACE

Hope it helps. If you need anything else, do not hesitate to ask.
Regards,
Alberto

Thank you so much Alberto!

I can’t believe that I missed that section on the GitHub page!

I think I got it all figured out now - thanks again!

All the best,
Anders

1 Like

Hey @andershansson, I just added some more pointers to the docs. Hopefully that’ll help whoever comes next!

1 Like