Docker client unable to connect to the Docker daemon while docker service is running

I am running a Dockerfile that (is supposed to) run a docker-compose.yml file for a different package, but currently returns an error.

The command

docker-compose -f /home/kasm-default-profile/Project-main/docker-compose.yml up -d --build 

fails because the Docker client cannot connect to the Docker daemon.

This is my Dockerfile:

FROM kasmweb/core-ubuntu-jammy:1.15.0
USER root

ENV HOME /home/kasm-default-profile
ENV STARTUPDIR /dockerstartup
ENV INST_SCRIPTS $STARTUPDIR/install
WORKDIR $HOME

######### Customize Container Here ###########

#get updates, install python 3.8, pip, unzip and docker's prerequisites && systemd installed#
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install software-properties-common
RUN apt-add-repository ppa:deadsnakes/ppa -y
RUN apt-get update
RUN apt-get install -y python3.10 python3-pip ca-certificates curl unzip systemd
RUN install -m 0755 -d /etc/apt/keyrings
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
RUN chmod a+r /etc/apt/keyrings/docker.asc

#run the command to add the repo to the Apt sources#
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
RUN sudo apt-get update

#installs docker#
RUN sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
RUN sudo apt-get update  
RUN sudo service docker start
RUN sudo /etc/init.d/docker start

#takes the Project zip, unzips it in container and runs docker compose#
COPY ./Project-main.zip /home/kasm-default-profile/
RUN unzip /home/kasm-default-profile/Project-main.zip
RUN rm /home/kasm-default-profile/Project-main.zip

RUN sudo apt-get install docker-compose -y
RUN docker-compose -f /home/kasm-default-profile/Project-main/docker-compose.yml up -d --build

######### End Customizations ###########

RUN chown 1000:0 $HOME
RUN $STARTUPDIR/set_user_permission.sh $HOME

ENV HOME /home/kasm-user
WORKDIR $HOME
RUN mkdir -p $HOME && chown -R 1000:0 $HOME

USER 1000

And this is the full error it returns:

> [22/29] RUN docker-compose -f /home/kasm-default-profile/Project-main/docker-compose.yml up -d --build:

0.525 Traceback (most recent call last):

0.525   File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 700, in urlopen

0.525     httplib_response = self._make_request(

0.525   File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 395, in _make_request

0.525     conn.request(method, url, **httplib_request_kw)

0.525   File "/usr/lib/python3.10/http/client.py", line 1283, in request

0.525     self._send_request(method, url, body, headers, encode_chunked)

0.525   File "/usr/lib/python3.10/http/client.py", line 1329, in _send_request

0.525     self.endheaders(body, encode_chunked=encode_chunked)

0.525   File "/usr/lib/python3.10/http/client.py", line 1278, in endheaders

0.525     self._send_output(message_body, encode_chunked=encode_chunked)

0.525   File "/usr/lib/python3.10/http/client.py", line 1038, in _send_output

0.525     self.send(msg)

0.525   File "/usr/lib/python3.10/http/client.py", line 976, in send

0.526     self.connect()

0.526   File "/usr/lib/python3/dist-packages/docker/transport/unixconn.py", line 30, in connect

0.526     sock.connect(self.unix_socket)

0.526 FileNotFoundError: [Errno 2] No such file or directory

0.526

0.526 During handling of the above exception, another exception occurred:

0.526

0.526 Traceback (most recent call last):

0.526   File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send

0.526     resp = conn.urlopen(

0.526   File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 756, in urlopen

0.526     retries = retries.increment(

0.526   File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 532, in increment

0.526     raise six.reraise(type(error), error, _stacktrace)

0.526   File "/usr/lib/python3/dist-packages/six.py", line 718, in reraise

0.526     raise value.with_traceback(tb)

0.526   File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 700, in urlopen

0.526     httplib_response = self._make_request(

0.526   File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 395, in _make_request

0.527     conn.request(method, url, **httplib_request_kw)

0.527   File "/usr/lib/python3.10/http/client.py", line 1283, in request

0.527     self._send_request(method, url, body, headers, encode_chunked)

0.527   File "/usr/lib/python3.10/http/client.py", line 1329, in _send_request

0.527     self.endheaders(body, encode_chunked=encode_chunked)

0.527   File "/usr/lib/python3.10/http/client.py", line 1278, in endheaders

0.527     self._send_output(message_body, encode_chunked=encode_chunked)

0.527   File "/usr/lib/python3.10/http/client.py", line 1038, in _send_output

0.528     self.send(msg)

0.528   File "/usr/lib/python3.10/http/client.py", line 976, in send

0.528     self.connect()

0.528   File "/usr/lib/python3/dist-packages/docker/transport/unixconn.py", line 30, in connect

0.528     sock.connect(self.unix_socket)

0.528 urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

0.528

0.528 During handling of the above exception, another exception occurred:

0.528

0.528 Traceback (most recent call last):

0.528   File "/usr/lib/python3/dist-packages/docker/api/client.py", line 214, in _retrieve_server_version

0.528     return self.version(api_version=False)["ApiVersion"]

0.528   File "/usr/lib/python3/dist-packages/docker/api/daemon.py", line 181, in version

0.528     return self._result(self._get(url), json=True)

0.528   File "/usr/lib/python3/dist-packages/docker/utils/decorators.py", line 46, in inner

0.528     return f(self, *args, **kwargs)

0.528   File "/usr/lib/python3/dist-packages/docker/api/client.py", line 237, in _get

0.528     return self.get(url, **self._set_request_timeout(kwargs))

0.528   File "/usr/lib/python3/dist-packages/requests/sessions.py", line 557, in get

0.528     return self.request('GET', url, **kwargs)

0.528   File "/usr/lib/python3/dist-packages/requests/sessions.py", line 544, in request

0.529     resp = self.send(prep, **send_kwargs)

0.529   File "/usr/lib/python3/dist-packages/requests/sessions.py", line 657, in send

0.529     r = adapter.send(request, **kwargs)

0.529   File "/usr/lib/python3/dist-packages/requests/adapters.py", line 498, in send

0.529     raise ConnectionError(err, request=request)

0.529 requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

0.529

0.529 During handling of the above exception, another exception occurred:

0.529

0.529 Traceback (most recent call last):

0.529   File "/usr/bin/docker-compose", line 33, in <module>

0.529     sys.exit(load_entry_point('docker-compose==1.29.2', 'console_scripts', 'docker-compose')())

0.529   File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 81, in main

0.529     command_func()

0.529   File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 200, in perform_command

0.529     project = project_from_options('.', options)

0.529   File "/usr/lib/python3/dist-packages/compose/cli/command.py", line 60, in project_from_options

0.529     return get_project(

0.529   File "/usr/lib/python3/dist-packages/compose/cli/command.py", line 152, in get_project

0.529     client = get_client(

0.529   File "/usr/lib/python3/dist-packages/compose/cli/docker_client.py", line 41, in get_client

0.529     client = docker_client(

0.529   File "/usr/lib/python3/dist-packages/compose/cli/docker_client.py", line 170, in docker_client

0.530     client = APIClient(use_ssh_client=not use_paramiko_ssh, **kwargs)

0.530   File "/usr/lib/python3/dist-packages/docker/api/client.py", line 197, in __init__

0.530     self._version = self._retrieve_server_version()

0.530   File "/usr/lib/python3/dist-packages/docker/api/client.py", line 221, in _retrieve_server_version

0.530     raise DockerException(

0.530 docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

------

Dockerfile:44

--------------------

  42 |

  43 |     RUN sudo apt-get install docker-compose -y

  44 | >>> RUN docker-compose -f /home/kasm-default-profile/Project-main/docker-compose.yml up -d --build

--------------------

ERROR: failed to solve: process "/bin/sh -c docker-compose -f /home/kasm-default-profile/Project-main/docker-compose.yml up -d --build" did not complete successfully: exit code: 1

The error is traced back to a python source code file, I need to use python3.8 for my project, which I have specified, but it sometimes mentions python3.10 which confuses me.

Any help would be greatly appreciated, thank you in advance.

New contributor

CodeCrafter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật