skip to Main Content

Is it possible to run docker-compose commands within a Docker container? As an example, I am trying to install https://datahubproject.io/docs/quickstart/ FROM within a Docker container that is built using the Dockerfile shown below. The Dockerfile creates a Linux container with the prerequisites the datahubproject.io project needs (Python) and clones the repository code to a Docker container. I then want to be able to execute the Docker compose scripts from the repository code (that is cloned to the newly built Docker container) to create the Docker containers needed to run the datahubproject.io project. This is not a docker commit question.

To try this, I have the following docker-compose.yml script:

version: '3.9'
# This is the docker configuration script    
services:
    datahub:
      # run the commands in the Dockerfile (found in this directory)
      build:
      # we need tty set to true to keep the container running after the build
      tty: true

…and a Dockerfile (to setup a Linux environment with the requirements needed for datahubproject.io quickstart):

FROM debian:bullseye
ENV DEBIAN_FRONTEND noninteractive

# install some of the basics our environment will need
RUN apt-get update && apt-get install -y 
    git 
    docker 
    pip 
    python3-venv

# clone the GitHub code
RUN git clone https://github.com/kuhlaid/datahub.git --branch master --single-branch

RUN python3 -m venv venv
#     # the `source` command needs the bash shell
SHELL ["/bin/bash", "-c"]
RUN source venv/bin/activate

RUN python3 -m pip install --upgrade pip wheel setuptools
RUN python3 -m pip install --upgrade acryl-datahub
CMD ["datahub version"]
CMD ["./datahub/docker/quickstart.sh"]

I run docker compose up from a command line where these two scripts are located to run the Dockerfile and create the start container that will be used to install the datahubproject.io project.

I receive this error:

datahub-datahub-1  | Quickstarting DataHub: version head
datahub-datahub-1  | Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
datahub-datahub-1  | No Datahub Neo4j volume found, starting with elasticsearch as graph service
datahub-datahub-1  | ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?

I do not know if what I am trying to do is even possible with Docker. Any suggestions to make this work? – thank you

2

Answers


  1. Chosen as BEST ANSWER

    The answer seems to be to modify the docker-compose.yml script to contain two additional settings:

    version: '3.9'
    # This is the docker configuration script    
    services:
        datahub:
          # run the commands in the Dockerfile (found in this directory)
          build: .
          # we need tty set to true to keep the container running after the build
          tty: true
          # ---------- adding the following two settings seems to fixes the issue of the `CMD ["./datahub/docker/quickstart.sh"]` failing in the Dockerfile 
          stdin_open: true
          volumes:
            - /var/run/docker.sock:/var/run/docker.sock
    

  2. Can docker-compose commands by executed from within a Docker container?

    Yes. A command like any other.

    Is it possible to run docker-compose commands from with a Docker container?

    Yes.

    Any suggestions to make this work?

    Like with docker on the host. Either run docker daemon or connect to one with DOCKER_HOST. DIND is relevant https://hub.docker.com/_/docker .

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search