yuk*_*lia 153 docker docker-compose docker-container
docker-compose.yml中定义了一系列服务.这些服务已经开始.我只需要重建其中一个并在没有其他服务的情况下启动它.我运行以下命令:
docker-compose up -d # run all services
docker-compose stop nginx # stop only one. but it still running !!!
docker-compose build --no-cache nginx
docker-compose up -d --no-deps # link nginx to other services
Run Code Online (Sandbox Code Playgroud)
最后我得到了旧的nginx容器.顺便说一句,docker-compose不会杀死所有正在运行的容器!
den*_*nov 177
$docker-compose up -d --no-deps --build <service_name>
Run Code Online (Sandbox Code Playgroud)
--no-deps - 不要启动链接服务.
--build - 在启动容器之前构建映像.
Har*_*rel 122
用docker-compose 1.19
docker-compose up -d --force-recreate --build
Run Code Online (Sandbox Code Playgroud)
从帮助菜单中
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.
Run Code Online (Sandbox Code Playgroud)
Arg*_*nQQ 49
这应该可以解决您的问题:
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
Run Code Online (Sandbox Code Playgroud)
Sla*_*ser 41
正如@HarlemSquirrel发布的那样,这是最好的,我认为是正确的解决方案.
但是,要回答OP特定的问题,它应该类似于以下命令,因为他不想在docker-compose.yml
文件中重新创建所有服务,而只需要重新创建nginx
:
docker-compose up -d --force-recreate --no-deps --build nginx
Run Code Online (Sandbox Code Playgroud)
选项说明:
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.
Run Code Online (Sandbox Code Playgroud)
小智 21
也许这些步骤不太正确,但我喜欢这样:
停止泊坞窗撰写: $ docker-compose down
警告:以下内容prune
将删除所有图像,您可能不希望这样做,因为它可能会影响其他项目。
移除容器: $ docker system prune -a
启动docker compose: $ docker-compose up -d
对我来说,它只从 Docker Hub 获取新的依赖项,同时包含--no-cache
和--pull
(可用于docker-compose build
.
# other steps before rebuild
docker-compose build --no-cache --pull nginx # rebuild nginx
# other steps after rebuild, e.g. up (see other answers)
Run Code Online (Sandbox Code Playgroud)
docker-compose stop nginx # stop if running
docker-compose rm -f nginx # remove without confirmation
docker-compose build nginx # build
docker-compose up -d nginx # create and start in background
Run Code Online (Sandbox Code Playgroud)
用 rm 删除容器是必不可少的。如果不删除,Docker 将启动旧容器。
问题是:
$ docker-compose stop nginx
Run Code Online (Sandbox Code Playgroud)
没用(你说它仍在运行)。如果你无论如何都要重建它,你可以尝试杀死它:
$ docker-compose kill nginx
Run Code Online (Sandbox Code Playgroud)
如果还是不行,尝试直接用docker停止:
$ docker stop nginx
Run Code Online (Sandbox Code Playgroud)
或删除它
$ docker rm -f nginx
Run Code Online (Sandbox Code Playgroud)
如果仍然不起作用,请检查您的 docker 版本,您可能需要升级。
这可能是一个错误,您可以检查是否与您的系统/版本匹配。这里有一些,例如: https ://github.com/docker/docker/issues/10589
https://github.com/docker/docker/issues/12738
作为解决方法,您可以尝试终止该进程。
$ ps aux | grep docker
$ kill 225654 # example process id
Run Code Online (Sandbox Code Playgroud)
小智 6
您可以使用:
docker-compose build
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 docker 配置文件:
docker-compose --profile profile_name build
Run Code Online (Sandbox Code Playgroud)
只需使用:
docker-compose build [yml_service_name]
Run Code Online (Sandbox Code Playgroud)
替换[yml_service_name]
为docker-compose.yml
文件中的服务名称。您可以使用docker-compose restart
来确保更改生效。您可以使用--no-cache
忽略缓存。
归档时间: |
|
查看次数: |
183008 次 |
最近记录: |