[英]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.我们试图在远程主机上构建和运行 docker-compose 项目。 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?这是 docker-compose 中的错误、功能还是我的环境中的错误?
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.我不确定您在第一个命令中遇到的错误,我的意思是docker-compose -H 'ssh://ip' up --build
因为它可能确实是一个但是,但是提到的三个命令肯定有区别。 I'll try to explain in my simple way:我将尝试以简单的方式解释:
docker-compose up --build
.第一个命令是docker-compose up --build
。 This command finds docker-compose
file and rebuilds the image then make it running.此命令查找docker-compose
文件并重建映像,然后使其运行。 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).假设您已经对docker-compose
文件进行了一些更改,所以当您只运行docker-compose
时,您会收到警告说图像未重建,您应该运行docker-compose up --build
重新构建它并重新构建它之前完成并存在于缓存中)。
docker-compose build
.第二个命令是docker-compose build
。 This command only builds your image based on docker-compose
, but does not run it.此命令仅基于docker-compose
构建您的映像,但不会运行它。 You can see the built image by docker image ls
or docker images
.您可以通过docker image ls
或docker images
查看构建的图像。 Also executing docker ps -a
should not see your recent built image running.同时执行docker ps -a
应该不会看到您最近构建的映像正在运行。
docker-compose up
.第三个也是最后一个命令是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.如果第一次输入此命令,它会尝试运行Dockerfile
中的所有内容(如果存在)并下载基础镜像等。然后制作镜像并运行容器。
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.与第一个命令不同,第三个命令仅运行该映像的最新构建,但不会再次构建它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.