2

Is there a command that I can evaluate (eval $COMMAND) or an environment variable that I can inspect to get the URI of the locally running docker host? I need to be this an expression to evaluate at runtime, since I need to use it in a script intended to run on hosts where docker engine may not be running on the standard ports.

Thanks.

5
  • The command on local docker host or the pc which run docker daemon & configured to use local docker host? Commented May 17, 2019 at 1:53
  • When from a terminal connected to the localhost I execute docker ps, that command goes to some docker engine. I want to resolve the URI of the daemon that answers to that command. Commented May 17, 2019 at 1:58
  • You should be able to get this from ${DOCKER_HOST} Commented May 17, 2019 at 2:02
  • 1
    I thought so; but that variable seems user preference more than docker state handled. I am running docker commands here and echo ${DOCKER_HOST} returns empty. Commented May 17, 2019 at 2:10
  • 1
    In my particular case, it is not a remote host, it is the local host. Somehow when I issue docker ..., the docker client knows how to reach a docker engine or fail trying, I just need a command that can evaluate to such URI, maybe even some docker utility? Commented May 17, 2019 at 2:47

2 Answers 2

3

I am not sure I have fully understood your question but hopefully this may shed some light.

The docker command is just a REST client. By default the client connects to the unix-socket /var/run/docker.sock to send requests to the docker daemon. You can practically achieve the same thing by running curl:

curl --unix-socket /var/run/docker.sock http:/localhost/version 

Now if your docker daemon was configured for remote access, you probably have the URI information in the docker.service service file. See this post How do I find the Docker REST API URL?.

Hope that helps

Sign up to request clarification or add additional context in comments.

1 Comment

Nice! that's exactly what I was looking for. I didn't have very clear how the client addressed the daemon though; but this totally clear things up in the direction I needed, thanks!
-1

Hey you can use ps command on the host and grep docker like below

>ps aux | grep docker root 1729 0.0 0.3 2222936 56288 ? Ssl May08 8:05 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock 

then you can get which port(s) or sock it is linked with

3 Comments

That doesn't give me the URI, nor portions of it reliably; and it most hosts there are plenty of entries in ps matching docker
then grep whole path /usr/bin/dockerd
It doesn't work. If you don't know, that's alright, no need to keep guessing or hacking away until finding something that may stick.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.