我已经安装了Docker,并且找不到简单的方法来删除容器。 Container是作为服务创建的:
version: '3.1'
services:
profiles:
image: mysql:8.0.3
environment:
- MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_pwd
secrets:
- mysql_root_pwd
secrets:
mysql_root_pwd:
file: /run/secrets/mysql_root_pwd
external: true
然而,我找不到一种简单的方法来阻止它(在高处和低处搜寻)。
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fc0bb42c3b1f mysql@sha256:21cc59a132e029c688734a66b50bfa7e5b31af9f2f19267f463c247d51c67b5a "docker-entrypoint..." 4 minutes ago Up 4 minutes 3306/tcp mysql803.1.t5zko7miwnkt37qk1ch6ubvmj
当我发出stop
命令时,我得到一个不同的容器ID:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9359e1e6ac3b mysql@sha256:21cc59a132e029c688734a66b50bfa7e5b31af9f2f19267f463c247d51c67b5a "docker-entrypoint..." 2 seconds ago Created mysql803.1.i7bktrg7631aetonf09nzahsk
fc0bb42c3b1f mysql@sha256:21cc59a132e029c688734a66b50bfa7e5b31af9f2f19267f463c247d51c67b5a "docker-entrypoint..." 6 minutes ago Exited (0) 2 seconds ago mysql803.1.t5zko7miwnkt37qk1ch6ubvmj
显然,我尝试设置RestartPolicy
:
sudo docker update --restart=no 9359e1e6ac3b
之前:
"RestartPolicy": {
"Name": "",
"MaximumRetryCount": 0
},
后:
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
但是,再一次,停止此容器会导致重新生成一个新容器。我也试过重启Docker守护进程,但没有成功。
任何人都可以指出解决这个愚蠢问题的正确方向吗?
更新
忘记提及可能有用的Docker特定信息:
Client:
Version: 1.13.1
API version: 1.26
Go version: go1.6.2
Git commit: 092cba3
Built: Thu Nov 2 20:40:23 2017
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Go version: go1.6.2
Git commit: 092cba3
Built: Thu Nov 2 20:40:23 2017
OS/Arch: linux/amd64
Experimental: false
答案 0 :(得分:0)
愚蠢的我,我找到了我错过的东西,我发布在这里以防其他人偶然发现同样的情况。
我尝试的是停止一个容器,这是一个具有1个副本的服务的一部分。作为回应,服务将重新生成一个新服务。
我不需要与容器交谈,而是需要将其用于服务。所以,这解决了问题:
> sudo docker service ls
ID NAME MODE REPLICAS IMAGE
msczwypom56z mysql803 replicated 1/1 mysql:8.0.3
> sudo docker service ps msczwypom56z
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
zkxlb9k04hb0 mysql803.1 mysql:8.0.3 ubuntu Running Running about a minute ago
hczlxonvykvs \_ mysql803.1 mysql:8.0.3 ubuntu Shutdown Failed about a minute ago "task: non-zero exit (137)"
w3i3yrxvbokd \_ mysql803.1 mysql:8.0.3 ubuntu Shutdown Shutdown about a minute ago
774squpmwnqf \_ mysql803.1 mysql:8.0.3 ubuntu Shutdown Complete 4 minutes ago
t5zko7miwnkt \_ mysql803.1 mysql:8.0.3 ubuntu Shutdown Complete 5 minutes ago
# Not sure if this was needed at all
sudo docker service update --restart-condition=none msczwypom56z
# Finally, remove it
sudo docker service rm msczwypom56z
运行docker ps
命令后,没有显示新容器。
希望这对某人有帮助......