Docker Community Forums

Share and learn in the Docker community.

How to operate docker command within dockerfile

build
docker

(Rukeith) #1

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


(Think) #2

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

(Rukeith) #3

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.


(Think) #4

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.