Multiple container app: execute container from another container

fenglovemilly 注册会员
2022-12-06 23:01

You should build both parts into a single unified image, and then you can use the Python subprocess module as normal to invoke the tool.

The standard Docker Hub python image is already built on Debian, which is very closely related to Ubuntu. So you should be able to do something like

FROM python:3.10

# Install OS-level dependencies for both the main application and
# the support tool
RUN apt-get update \
 && DEBIAN_FRONTEND=noninteractive \
    apt-get install --no-install-recommends --assume-yes \
      another-dependency \
      some-dependency \

# Install the support tool
ADD http://repository.example.com/the-tool/the-tool /usr/local/bin/the-tool
RUN chmod +x /usr/local/bin/the-tool

# Copy and install Python-level dependencies
COPY requirements.txt ./
RUN pip install -r requirements.txt

# Copy in the main application
COPY ./ ./

# Metadata on how to run the application
# USER someuser
CMD ["./the-app.py"]

You've already noted the key challenges in having the tool in a separate container. You can't normally "run commands" in a container; a container is a wrapper around some single process, and it requires unrestricted root-level access to the host to be able to manipulate the container in any way (including using the docker exec debugging tool). You'd also need unrestricted root-level access to the host to be able to launch a temporary container per request.

Putting some sort of API or job queue around the tool would be the "most Dockery" way to do it, but that can also be significant development effort. In this setup as you've described it, the support tool is mostly an implementation detail of the main process, so you're not really breaking the "one container does one thing" rule by making it available for a normal Unix subprocess invocation inside the same container.

About the Author

Question Info

Publish Time
2022-12-06 23:01
Update Time
2022-12-06 23:01