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 get.docker.com -o get-docker.sh && \
    sh get-docker.sh && \
    usermod -aG docker daemon && \
    curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`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?
16

docker in docker is usually just used for testing new docker versions…but even there it has side effects.
Details: http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/

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