I have a Dockerfile that I'm using to build a runtime environment for some bash scripts, currently it looks like this:

FROM debian:buster-slim

RUN apt-get update
RUN apt-get upgrade

RUN apt-get install curl -y

# Install MySQL tools
RUN apt-get install default-mysql-client -y

# Install AWS CLI v2
RUN apt-get install awscli -y

# Install Docker
RUN curl -fsSL https://get.docker.com -o get-docker.sh
RUN chmod +x ./get-docker.sh
RUN ./get-docker.sh
RUN rm get-docker.sh

# Copy jobs into container

COPY ./docker-entrypoint.sh /

ENTRYPOINT ["/docker-entrypoint.sh"]

The docker-entrypoint.sh script contains the following:


docker --version

Finally, the job that I'm running (the run.sh script that ends up being run by docker-entrypoint.sh) looks like this:

docker --version

The first execution of docker --version inside of docker-entrypoint.sh behaves as expected and outputs the Docker version. The second execution from run.sh fails to run with the following message:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

For some reason it seems like the inner script doesn't have access to the docker daemon while the outer script does.

Interestingly, if I actually run ./docker-entrypoint.sh [job-name] locally, instead of within the Docker container, I get the expected output from BOTH executions.

Is anyone able to explain why this is occurring and help with a solution?

1 Answer 1


The Docker socket isn’t automatically made available inside running containers; you need to mount it explicitly:

docker run -v /var/run/docker.sock:/var/run/docker.sock ...

(with appropriate suffixes, e.g. :z if SELinux is enabled).

docker --version works without the socket because it doesn’t need the Docker socket; it returns the tool’s version without contacting the daemon when /var/run/docker.sock doesn’t exist. The scripts in the container must be running some other docker command.

  • Both scripts are being run inside the same container - the first script (docker-entrypoint.sh) is able to use docker just fine, the second script (run.sh - executed as part of the first script) cannot use docker.
    – Nick Coad
    Dec 6, 2021 at 8:13
  • 1
    docker --version doesn’t need the Docker socket. Dec 6, 2021 at 8:18
  • And yet, it fails with an error message saying that it does. I don't know why, it's possible that the error message is a red herring. The key point here is that the same command works in one script, but not the other. BOTH scripts are simply calling docker --version.
    – Nick Coad
    Dec 6, 2021 at 8:19
  • And there’s no other docker command in your scripts? Dec 6, 2021 at 8:22
  • No, I posted the scripts in full. You can copy them and run it yourself to see the problem I'm experiencing.
    – Nick Coad
    Dec 6, 2021 at 8:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .