0

So, I'm trying to run docker inside Dockerfile ("the best idea ever") using command sudo docker service start but it's always responds with

#9 0.142 mkdir: cannot create directory ‘cpuset’: Read-only file system
------

Dockerfile looks like this.



FROM jenkins/jenkins:lts

USER root
RUN apt-get update && apt-get upgrade -y


RUN apt-get update && \
apt-get -y install apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common && \
apt-get update && \
apt-get -y install docker.io && \
apt-get -y install sudo

RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -

RUN add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/debian \
   $(lsb_release -cs) \
   stable"

VOLUME /var/run/docker.sock
RUN sudo service docker start  ///////1111111\\\\\\\\ The Error goes there.....

RUN adduser jenkins sudo
RUN echo “jenkins ALL=NOPASSWD: ALL” >> /etc/sudoers

RUN usermod -aG docker jenkins
RUN chown root:jenkins /var/run/docker.sock

USER jenkins

From the Error Response, Seems like I need to enable Write Mode,there are many solutions/suggestions for that, but most of them unfortunately does not work....

Can it be the problem related to Image?

Would really appreciate any suggestions/tips, (but more likely the solution :))

CraZyCoDer
  • 367
  • 1
  • 2
  • 16
  • Why would one run docker inside a docker container? – Dima Chubarov Jul 19 '22 at 21:14
  • See also https://stackoverflow.com/questions/27879713/is-it-ok-to-run-docker-from-inside-docker – Nick ODell Jul 19 '22 at 22:33
  • While it's theoretically possible to run a secondary Docker daemon inside a Docker container, it's an advanced topic and usually discouraged. I'd suggest becoming much more familiar with Docker before considering it; for example, a Docker image doesn't persist running services, so a `RUN` command that starts a daemon has no actual effect. – David Maze Jul 19 '22 at 23:23
  • @DavidMaze, the Problem is that my Jenkins Server need to execute some docker commands inside my Pipeline, so but there is no docker pre-installed in that container, so what I'm trying to achieve, is to install docker inside container and add Jenkins user to the Docker Group in Order to execute some operations. – CraZyCoDer Jul 19 '22 at 23:28
  • [Docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock](https://stackoverflow.com/questions/47854463/docker-got-permission-denied-while-trying-to-connect-to-the-docker-daemon-socke) might better describe your actual problem. However, note that the question has a lot of extremely insecure answers; any of the multiple answers that suggest `chmod ... /var/run/docker.sock` risk compromising your system. – David Maze Jul 19 '22 at 23:28
  • [Docker not found when building docker image using Docker Jenkins container pipeline](https://stackoverflow.com/questions/44850565/docker-not-found-when-building-docker-image-using-docker-jenkins-container-pipel) might be even better for you. – David Maze Jul 19 '22 at 23:29
  • @DavidMaze, Exactly what I need :), (I'm about the first one), But in the first example it uses some sudo commands, (I'm actually running MacOS, and the Jenkins Server is running inside docker container), So Do you know how to apply the same logic from the first example but for `Jenkins, that is running inside Docker Container`? – CraZyCoDer Jul 19 '22 at 23:34
  • @DavidMaze, Do not really expect any Answers on my questions from you, I think, you've already Done a lot, to help me to solve this issue. So, Thanks Anyway :P – CraZyCoDer Jul 19 '22 at 23:37

1 Answers1

0

Even if you wanted to run docker inside docker, you would not start the docker daemon during container build time but rather at container run time.

That means move the 'sudo service docker start' command into your entrypoint script.

Queeg
  • 7,748
  • 1
  • 16
  • 42