10

We were trying to build and run docker-compose project on remote host. I tried using:

docker-compose -H 'ssh://remote_address' up --build

And got

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

So we tried:

docker-compose -H 'ssh://remote_address' build
docker-compose -H 'ssh://remote_address' up

Which worked fine. My problem is I can't find evidence in docs for this to be correct behaviour. Is this a bug in docker-compose, a feature, or a bug in my environment?

1

1 Answer 1

10

I'm not sure of the error you got for the first command, I mean docker-compose -H 'ssh://ip' up --build as it may be really a but, but the three mentioned commands have surely differences. I'll try to explain in my simple way:

  1. First command is docker-compose up --build.

This command finds docker-compose file and rebuilds the image then make it running. Suppose you have made some changes into your docker-compose file, so when you only run docker-compose, you'll get a warning that image is not rebuilt, you should run docker-compose up --build to rebuild it and make everything be built again (despite something done before and present in cache).

  1. Second command is docker-compose build.

This command only builds your image based on docker-compose, but does not run it. You can see the built image by docker image ls or docker images. Also executing docker ps -a should not see your recent built image running.

  1. Third and the last command is docker-compose up.

If this command is entered for the first time, it tries to run everything in Dockerfile if exists and download base image, etc. Then makes the image and runs the container.

If the image has been built before, it just runs it.

Unlike the first command, the third one only runs the latest build of that image, but would not build it again.

3
  • Thanks for explanation, however my problem lies in -H flag interpretation. It appears that docker-compose up --build ignores it and tries to connect to default docker engine on unix:///var/run/docker.sock which is unavailable in my environment.
    – Jakub Noga
    Mar 25, 2021 at 8:18
  • I've read the manual of docker for -H, and it seems the socket on Host server (in your case, your remote ssh server) should be running. If I've understood it correctly, have you checked if docker is running in remote server?
    – Saeed
    Mar 25, 2021 at 8:26
  • 1
    As I wrote in question remote Docker Engine is running and everything works as expected when I use docker-compose -H 'ssh://remote_host' build && docker-compose -H 'ssh://remote_host' up instead of docker-compose -H 'ssh://remote_host' up --build
    – Jakub Noga
    Mar 25, 2021 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.