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.

Marco R.
  • 2,667
  • 15
  • 33
  • The command on `local docker host` or `the pc which run docker daemon & configured to use local docker host`? – atline May 17 '19 at 01: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. – Marco R. May 17 '19 at 01:58
  • You should be able to get this from `${DOCKER_HOST}` – DazWilkin May 17 '19 at 02: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. – Marco R. May 17 '19 at 02: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? – Marco R. May 17 '19 at 02:47

2 Answers2

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

b0gusb
  • 4,283
  • 2
  • 14
  • 33
  • 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! – Marco R. May 17 '19 at 13:57
  • I am glad it helped – b0gusb May 17 '19 at 14:34
-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

Nitish Mowall
  • 139
  • 1
  • 11