Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference in docker-compose up --build vs. docker-compose build && docker-compose up

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?

like image 568
Jakub Noga Avatar asked Nov 06 '22 02:11

Jakub Noga


1 Answers

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.

like image 128
Saeed Avatar answered Nov 15 '22 05:11

Saeed