Pass Docker run command through dockerfile

7/5/2018

I am trying to run docker inside my container. I saw in some of the article that I need to pass --privileged=true to make this possible.

But for some reason, I do not have the option to pass this parameter while running.. because it is been taken care by some automation which I do not have access.

So, I was wondering if its possible to pass above option in Dockerfile, so that I do not have the pass this as param.

Right now this is the content of my dockerfile.

FROM my-repo/jenkinsci/jnlp-slave:2.62

USER root
#RUN --privileged=true this doesnt work for obvious reasons
MAINTAINER RD_TOOLS "abc@example.com"
RUN apt-get update
RUN apt-get remove docker docker-engine docker.io || echo "No worries"
RUN apt-get --assume-yes install \
     apt-transport-https \
     ca-certificates \
     curl \
     gnupg2 \
     software-properties-common curl
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN apt-key fingerprint 0EBFCD88
RUN cat /etc/*-release
RUN apt-get --assume-yes install docker.io
RUN docker --version
RUN service docker start

WIthout passing privilaged= true param, it seems I cant run the docker inside docker.

Any help in this regard is highly appreciated.

-- kaounKaoun
docker
docker-compose
dockerfile
kubernetes

1 Answer

7/5/2018

You can't force a container to run as privileged from within the Dockerfile.

As a general rule, you can't run Docker inside a Docker container; the more typical setup is to share the host's Docker socket. There's an official Docker image that attempts this at https://hub.docker.com/_/docker/ with some fairly prominent suggestions to not actually use it.

-- David Maze
Source: StackOverflow