我正在jenkins的官方码头集装箱上运行jenkins。我按照https://docs.docker.com/engine/installation/linux/debian/
上的说明进行了以下dockerfile
FROM jenkins:2.32.1
# install docker inside this container
USER root
# Install Docker inside Jenkins
RUN apt-get update
RUN apt-get purge "docker.io*"
RUN apt-get update
RUN apt-get install -y apt-transport-https ca-certificates gnupg2
RUN apt-key adv \
--keyserver hkp://ha.pool.sks-keyservers.net:80 \
--recv-keys 58118E89F3A912897C070ADBF76221572C52609D
RUN echo "deb https://apt.dockerproject.org/repo debian-jessie main" > /etc/apt/sources.list.d/docker.list
RUN apt-get update
RUN apt-cache policy docker-engine
RUN apt-get update
RUN apt-get install -y docker-engine
RUN gpasswd -a jenkins docker
USER jenkins
然后我执行以下操作:
sudo docker service start
这是我得到的:
root@1e0f4b325d58:/# sudo service docker start
mount: permission denied
rmdir: failed to remove ‘cpu’: Read-only file system
mount: permission denied
rmdir: failed to remove ‘cpuacct’: Read-only file system
mount: permission denied
rmdir: failed to remove ‘net_cls’: Read-only file system
mount: permission denied
rmdir: failed to remove ‘net_prio’: Read-only file system
/etc/init.d/docker: 96: ulimit: error setting limit (Operation not permitted)
答案 0 :(得分:4)
如果要在docker中运行docker,则需要将容器作为特权容器运行。
因此需要something like this(1):
docker run --privileged your_image:tag
你还需要小心使用iptables和App Armor,但这需要经过一些修补。
另一种方法是访问容器内的docker守护程序,like so(2):
docker run -v /var/run/docker.sock:/var/run/docker.sock your_image:tag
价:
1 https://blog.docker.com/2013/09/docker-can-now-run-within-docker/
2 https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/