How to operate docker command within dockerfile

I want to use docker command inside image

Here is my Dockerfile

FROM ubuntu:16.04
USER root
RUN apt-get update -y && \
    apt-get install -y curl && \
    curl -fsSL -o && \
    sh && \
    usermod -aG docker daemon && \
    curl -L`uname -s`-`uname -m` -o /usr/local/bin/docker-compose && \
    chmod +x /usr/local/bin/docker-compose && \
    service docker start && \
    docker ps && \
    docker-compose --version

But I got this error. How could I fix this?

docker in docker is usually just used for testing new docker versions…but even there it has side effects.

depending on your use case, you probably should consider different approaches. you could:

  • just install the docker client and map the docker socket from outside in
  • map docker socket and docker binary from outside in
  • put your compose app into just a single docker file
  • provide your software as docker-stack-file

I try to use docker to run a docker compose to test my project.
So I want to build a image with docker compose.
I am not sure is it possible to use docker in side docker.

i would prefer to mount in your docker.sock into your docker or to use probably Vagrant to set up your defined lightweight docker compose environment.

1 Like