desktop-linux
desktop-linux copied to clipboard
Can we run Docker in Docker based on Ubuntu22.04?
Description
We are trying to run Docker inside docker container hosted on top of AKS v1.27. This was working on Ubuntu18 based image, but not working same way on Ubuntu22.04.
The issue is that Docker is not getting started on this created scaledjob contaianers, where as manually executing the command inside the container "service docker start" starting the docker service. Also when we run docker.sh
first time in the container getting below error, but when rerun again second time same script, starting the docker service.
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Base image as below
FROM ubuntu:22.04
#2-Enable Ubuntu Packages
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
wget \
&& rm -rf /var/lib/apt/lists/*
#install docker daemon inside docker
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
RUN echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
RUN apt-get update
RUN apt-get install docker-ce docker-ce-cli containerd.io -y
WORKDIR /azp
COPY ./vstsagent/ .
COPY ./start.sh .
COPY ./docker.sh .
RUN chmod +x start.sh docker.sh
CMD ["./docker.sh"]
ENTRYPOINT ["./start.sh"]
The ado Image created from above base image as below..
FROM myregistry/agetImage
RUN apt-get install docker-ce docker-ce-cli containerd.io -y
COPY ./daemon.json /etc/docker/
COPY ./config.json /root/.docker/
WORKDIR /azp/
RUN rm -rf start.sh
COPY ./start.sh .
RUN rm -rf docker.sh
COPY ./docker.sh .
RUN sed -i 's/ulimit -Hn/# ulimit -Hn/g' /etc/init.d/docker
RUN chmod 777 start.sh
RUN chmod 777 docker.sh
RUN usermod -aG docker root
ENV AGENT_ALLOW_RUNASROOT="true"
CMD ["./docker.sh"]
ENTRYPOINT [ "./start.sh"]
docker.sh as below
#!/bin/bash
echo "DOCKER STARTS HERE"
service docker start
docker version
docker ps
daemon.json as below
{
"storage-driver": "vfs"
}
scaledjob as below
apiVersion: keda.sh/v1alpha1
kind: ScaledJob
spec:
jobTargetRef:
template:
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference:
matchExpressions:
- key: kubernetes.azure.com/mode
operator: Exists
values:
- xxxxxxxxxxxxxxx
- key: topology.disk.csi.azure.com/zone
operator: Exists
values:
- westeurope-2
weight: 2
containers:
- name: xxxxxxxxxxxx
image: myregistry/vstsnew/vsts_customxxxx
imagePullPolicy: Always
resources:
limits:
cpu: 1500m
memory: 10Gi
requests:
cpu: 500m
memory: 6Gi
securityContext:
allowPrivilegeEscalation: true
privileged: true
env:
- name: AZP_URL
value: xxxxxxxxxxxxxxxxxxxxx
- name: AZP_TOKEN
value: xxxxxxxxxxxxxxxxxxxxxxxxxxxx
- name: AZP_POOL
value: xxxxxxxxxxxx
- name: AZP_AGENT_NAME
value: DockerAgentLinux
volumeMounts:
- mountPath: /mnt
name: xxxxxxxxxxxxx
nodeSelector:
agentpool: xxxxxxxxxxxxxxxx
volumes:
- name: xxxxxxxx
persistentVolumeClaim:
claimName: xxxxxxxxxxxxxxxxxx
pollingInterval: 30
successfulJobsHistoryLimit: 5
failedJobsHistoryLimit: 5
maxReplicaCount: 6
minReplicaCount: 1
scalingStrategy:
strategy: "default"
triggers:
- type: azure-pipelines
metadata:
poolID: "xxxx"
organizationURLFromEnv: "AZP_URL"
personalAccessTokenFromEnv: "AZP_TOKEN"
Reproduce
Docker in docker based on Ubuntu
Expected behavior
No response
docker version
Docker 20.03
docker info
Docker 20.03
Diagnostics ID
Service docker start
Additional Info
No response