4

I want to replace the below command with docker python sdk

docker exec 6d9c9b679541 /u01/app/oracle/product/12.0.0/dbhome_1/bin/sqlplus sachin/sachin@orcl @1.sql

here is code i am writing and the error i am getting using python3

>>> import docker
>>> client = docker.from_env()
>>> client.exec_run('6d9c9b679541',command='/u01/app/oracle/product/12.0.0/dbhome_1/bin/sqlplus sachin/sachin@orcl @1.sql')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/docker/client.py", line 205, in __getattr__
    raise AttributeError(' '.join(s))
AttributeError: 'DockerClient' object has no attribute 'exec_run'

How to resolve this issue?

1 Answer 1

10
+50

The from_env method returns a DockerClient object (docs here).

You need to get the container first, and then use the exec_run method. If you want to access a running container, you need the following:

container = client.containers.get('your_container_name_or_id')

Now you can run your command in the container:

container.exec_run('your command here')
Sign up to request clarification or add additional context in comments.

1 Comment

How to read stdout from the ExecResult?

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.