dockerpy

python docker how to mount the directory from host to container

独自空忆成欢 提交于 2020-05-15 05:11:25
问题 can someone please share some examples of py apis showing how to mount the directories ? I tried like this but I dont see its working dockerClient = docker.from_env() dockerClient.containers.run('image', 'ls -ltr', volumes={os.getcwd(): {'bind': '/tmp/', 'mode': 'rw'}}) 回答1: By getting the container object Change your code according to the following: import os import docker client = docker.from_env() container = client.containers.run('ubuntu:latest', 'ls -ltr /tmp', volumes={os.getcwd(): {

standard_init_linux.go:211:exec user process caused “no such file or directory” with alpine linux and python

浪尽此生 提交于 2020-01-25 08:34:10
问题 I have a directory which contains the docker file, a attack.py and a requirements.txt. Using that, I created the following dockerfile: FROM arm64v8/python:3.7-alpine COPY qemu-arm-static /usr/bin COPY ./ app-ids WORKDIR /app-ids RUN pip install --no-cache-dir -r requirements.txt CMD["python","./attack.py"] However, the pip install line throws: standard_init_linux.go:211:exec user process caused "no such file or directory" I can't figure out why. Using commands like ls, pwd and so on in an

How to copy a file from host to container using docker-py (docker SDK)

牧云@^-^@ 提交于 2020-01-23 06:42:25
问题 I know, there is possible way how to copy file bidirectionally between host and docker container using docker cp and also it is possible to obtain file from running container using docker-py. But I am not able to figure out how (or if it is even possible) copy file from host to running container using docker-py. Do you guys have any experiences with such kind of problem? Is it possible to do or I have to execute command using python os.system . I would like to avoid this solution. 回答1:

How can I detect when docker-py client.build() fails

那年仲夏 提交于 2020-01-04 05:24:14
问题 I'm using docker-py to build and run Docker images. From reading the documentation it isn't clear to me how I'm supposed to detect if there was an error building the image. build() doesn't raise an exception when there's an error. That makes me think I have to investigate the responses coming back. What's the best way to determine if docker-py's client.build() fails? 回答1: It looks like the 'best' way is to decode the response and look for a key named 'error'. For example: for response in

Docker remote api pull from Docker hub private registry

落花浮王杯 提交于 2019-12-30 03:19:26
问题 I'm trying to pull docker images from a private repository hosted in Docker hub https://registry.hub.docker.com/u/myname/myapp like this using the docker remote API. The doc is not clear as to how to specify the authentication credentials in a POST request like this curl -XPOST -H "X-Registy-Auth: base64_encoded_authconfig_object" "http://localhost:4243/images/create?fromImage=myname/myapp" This also does not elaborate on how exactly the authconfig is generated. This talks about sending in a

Capturing output of python script run inside a docker container

℡╲_俬逩灬. 提交于 2019-12-29 14:16:10
问题 The aim here is to use a docker container as a secure sandbox to run untrusted python scripts in, but to do so from within python using the docker-py module, and be able to capture the output of that script. I'm running a python script foo.py inside a docker container (it's set as the ENTRYPOINT command in my Dockerfile, so it's executed as soon as the container is run) and am unable to capture the output of that script. When I run the container via the normal CLI using docker run -v /host

Capturing output of python script run inside a docker container

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-29 14:13:28
问题 The aim here is to use a docker container as a secure sandbox to run untrusted python scripts in, but to do so from within python using the docker-py module, and be able to capture the output of that script. I'm running a python script foo.py inside a docker container (it's set as the ENTRYPOINT command in my Dockerfile, so it's executed as soon as the container is run) and am unable to capture the output of that script. When I run the container via the normal CLI using docker run -v /host

Host key verification failed when building image with docker-compose from a private repo over ssh

萝らか妹 提交于 2019-12-24 11:27:19
问题 Inside my docker-compose.yml I'm using ssh address context to build a Docker image. ui: build: context: git@my.git.host:ui/ui.git dockerfile: Dockerfile.prod container_name: ui ports: - "4200:4200" command: ember serve Running docker-compose build ui gives me : compose.cli.verbose_proxy.proxy_callable: docker build -> <generator object APIClient._stream_helper at 0x7faa8bc107d8> ERROR: compose.cli.errors.log_api_error: error fetching: Host key verification failed. fatal: Could not read from

How to upgrade docker container with previous network and volumes?

爱⌒轻易说出口 提交于 2019-12-12 04:47:18
问题 I'm developing an app where we pop containers with volumes and custom network. I need to add the feature where admin will be able to upgrade the running container to latest version. So I was hoping to be able to fetch the various information from it the pop a new container with the old config. Question However I'm not sure what I really need to grab on the old container and how to use it. For instance, Is NetworkSettings.Networks enough or is there network information elsewhere in the data ?

How to bind volumes in docker-py?

大城市里の小女人 提交于 2019-12-10 14:21:54
问题 I think this used to work up to a few months ago. The regular commandline docker: >> docker run --name 'mycontainer' -d -v '/new' ubuntu /bin/bash -c 'touch /new/hello.txt' >> docker run --volumes-from mycontainer ubuntu /bin/bash -c 'ls new' >> hello.txt works as expected but I cannot get this to work in docker-py: from docker import Client #docker-py import time docker = Client(base_url='unix://var/run/docker.sock') response1 = docker.create_container('ubuntu', detach=True, volumes=['/new']