Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions conan/internal/runner/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,26 @@ def __init__(self, conan_api, command, host_profile, build_profile, args, raw_ar
import docker
import docker.api.build
try:
self.docker_client = docker.from_env()
self.docker_api = docker.APIClient()
docker_base_urls = [
None, # Default docker configuration, let the python library detect the socket
os.environ.get('DOCKER_HOST'), # Connect to socket defined in DOCKER_HOST
'unix:///var/run/docker.sock', # Default linux socket
f'unix://{os.path.expanduser("~")}/.rd/docker.sock' # Rancher linux socket
]
for base_url in docker_base_urls:
try:
ConanOutput().verbose(f'Trying to connect to docker "{base_url or "default"}" socket')
self.docker_client = docker.DockerClient(base_url=base_url, version='auto')
ConanOutput().verbose(f'Connected to docker "{base_url or "default"}" socket')
break
except:
continue
self.docker_api = self.docker_client.api
docker.api.build.process_dockerfile = lambda dockerfile, path: ('Dockerfile', dockerfile)
except:
raise ConanException("Docker Client failed to initialize."
"\n - Check if docker is installed and running"
"\n - Run 'pip install pip install conan[runners]'")
"\n - Run 'pip install conan[runners]'")
self.conan_api = conan_api
self.build_profile = build_profile
self.args = args
Expand Down
5 changes: 4 additions & 1 deletion test/integration/command/runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

def docker_skip(test_image=None):
try:
docker_client = docker.from_env()
try:
docker_client = docker.from_env()
except:
docker_client = docker.DockerClient(base_url=f'unix://{os.path.expanduser("~")}/.rd/docker.sock', version='auto') # Rancher
if test_image:
docker_client.images.pull(test_image)
except docker.errors.DockerException:
Expand Down