简体   繁体   中英

Docker: No such file or directory when trying to run docker inside docker

Is docker binaries not available within docker? If so, how could I call it within docker?

app.py

import subprocess
cmd_payload = ['docker']
subprocess.Popen(cmd_payload, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

Dockerfile

FROM python:2.7-slim
VOLUME /data
WORKDIR /data
ADD . /data
CMD ["python", "app.py"]

Then, run

docker build -t app .
docker run app

OUTOUT:

[Errno 2] No such file or directory

EDIT: if i change

cmd_payload = ['docker'] 

to

cmd_payload = ['echo']

it doesnt throw an error. I would like to run docker executable . How could i do that?

If you want to run docker within of a container, the easy way to reach that is share docker daemon by volumes, Re-run your docker container with this:

docker run -it -v /var/run/docker.sock:/var/run/docker.sock:ro -v /usr/bin/docker:/usr/bin/docker:ro app

Moreover you have to add the library to Dockerfile

FROM python:2.7-slim
RUN apt-get update && apt-get install -y libltdl7 && rm -rf /var/lib/apt/lists/*
VOLUME /data
WORKDIR /data
ADD . /data
CMD ["python", "app.py"]

subprocess was able to run docker executable by adding shell=True

cmd_payload = 'docker'
subprocess.Popen(cmd_payload, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

Not sure why it couldnt find it if not invoked under a shell

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM