docker-compose.yml中定义了服务范围。这些服务已经启动。我只需要重新构建其中一个,并在不启动其他服务的情况下启动它。 执行如下命令:

docker-compose up -d # run all services
docker-compose stop nginx # stop only one. but it is still running !!!
docker-compose build --no-cache nginx 
docker-compose up -d --no-deps # link nginx to other services

最后,我得到了旧的nginx容器。 Docker-compose不会杀死所有正在运行的容器!


当前回答

你可以使用:

docker-compose build

如果你正在使用docker配置文件:

docker-compose --profile profile_name build

其他回答

这应该可以解决你的问题:

docker-compose ps # lists all services (id, name)
docker-compose stop <id/name> #this will stop only the selected container
docker-compose rm <id/name> # this will remove the docker container permanently 
docker-compose up # builds/rebuilds all not already built container 

简单地使用:

docker-compose build [yml_service_name]

在docker-compose中将[yml_service_name]替换为您的服务名。yml文件。您可以使用docker-compose restart来确保更改生效。你可以使用——no-cache来忽略缓存。

docker-compose起来

$ docker-compose up -d --no-deps --build <service_name>

——no-deps——不要启动链接服务。

——build——在启动容器之前构建镜像。

只有:

$ docker-compose restart [yml_service_name]

正如@HarlemSquirrel所述,这是最好的,我认为是正确的解决方案。

但是,为了回答OP特定的问题,它应该类似于下面的命令,因为他不想在docker-compose中重新创建所有服务。Yml文件,但只有nginx文件:

docker-compose up -d --force-recreate --no-deps --build nginx

方案描述:

Options:
  -d                  Detached mode: Run containers in the background,
                      print new container names. Incompatible with
                      --abort-on-container-exit.
  --force-recreate    Recreate containers even if their configuration
                      and image haven't changed.
  --build             Build images before starting containers.
  --no-deps           Don't start linked services.