0

I can find all of the ingredients for what I want to do, but I'm not sure if I can put them together.

Ultimately, I want a Python process to be able to create and manage Docker instances running on Azure.

This link shows that you can use the Docker API to fire up instances on Azure: https://docs.docker.com/engine/context/aci-integration/. It's Beta, but I've been able to run my own container on Azure after logging in, using something like this:

docker --context myacicontext run hello-world

The second half of my problem is to call this from docker-py. The vanilla usage of docker-py is nice and striaght-forward, but I can't find any reference to the flag "--context" in the docker-py docs (https://docker-py.readthedocs.io/en/stable/).

Is there a way for configuring docker-py such that it provides a --context?


EDIT:

Thanks to @CharlesXu pointing me in the right direction, I have now found that the following docker-py command does have an effect:

docker.context.ContextAPI.set_current_context("myacicontext")

This changes the default context used by the docker cmd line interface, so

C:\Users\MikeSadler>docker ps -a

will subsequently list the containers running in Azure, and not locally.

However, the docker.from_env().containers.list(all=all) command stubbornly continues to return the local containers. This is true even if you restart the Python session and create a new client from a completely fresh start.


CONCLUSION:

Having spoken with the Docker developers, as of October 2020 docker-py officially does not support Cloud connections. They are currently using GRPC protocols to manage Cloud runs, and this may be incorporated into docker-py in the future.

2
  • It seems like the context is set while building the image: docker-py.readthedocs.io/en/1.6.0/api Commented Oct 26, 2020 at 17:16
  • @CasperDijkstra I believe that is where the Docker daemon that you are speaking with is, rather than what is given to that daemon as the --context. I am already running this Python within a container, and the Python is using the host container's daemon to run docker. I need to provide that daemon with this context... Commented Oct 26, 2020 at 17:33

1 Answer 1

1

I'm afraid there is no way to do things like the command docker --context myacicontext run hello-world does. And there is also no parameter like --context in the SDK. As I know, you can set the current context use the SDK like this:

import docker
docker.context.config.write_context_name_to_docker_config('context_name')

But when you use the code:

client = docker.from_env()
client.containers.run('xxx')

Then it will set the context into default. It means you cannot run the containers into ACI. I think it may be a bug that needs to be fixed. I'm not very very sure, but that's it right now.

Sign up to request clarification or add additional context in comments.

11 Comments

Thanks - I hadn't found the write_context_name_to_docker_config function yet. Have you reported it as a bug? The fact that they have a context at all suggests that they intend to support it...
@MikeSadler I didn't report it as a bug because I'm not very sure. You still don't find the function?
Thanks, Charles. There's definitely something there. docker.context.ContextAPI.get_context("azure_context") returns an object which knows it is an "aci" context, so it looks like there is some real functionality there. I will experiment...
docker.context.ContextAPI.set_current_context("hhhoih") also returns an error (i.e. if the context does not exist). However, docker.from_env() is still ignoring it...
@MikeSadler That's the issue I found and told you in the answer. So I think it may be a bug.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.