运行 Ubuntu 服务器 22.04.4 LTS。
今天我做了一个apt update
并apt upgrade
运行了一些更新,然后我通过提取了新的docker镜像docker-compose pull
。在我尝试通过docker-compose重新启动容器后,我收到了一堆关于容器配置的错误,许多容器拒绝启动。然后当我运行时docker ps -a
,我看到一堆容器名称已更改为在先前的名称之前包含一个随机字符串(例如swag现在是5f6bfe94c235_swag)。我没有更改文件中的任何内容docker-compose.yml
,在此之前它一直运行良好。
当我运行时sudo docker-compose up -d
,我得到以下输出:
Traceback (most recent call last):
File "/usr/bin/docker-compose", line 33, in <module>
sys.exit(load_entry_point('docker-compose==1.29.2', 'console_scripts', 'docker-compose')())
File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 81, in main
command_func()
File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 203, in perform_command
handler(command, command_options)
File "/usr/lib/python3/dist-packages/compose/metrics/decorator.py", line 18, in wrapper
result = fn(*args, **kwargs)
File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 1186, in up
to_attach = up(False)
File "/usr/lib/python3/dist-packages/compose/cli/main.py", line 1166, in up
return self.project.up(
File "/usr/lib/python3/dist-packages/compose/project.py", line 697, in up
results, errors = parallel.parallel_execute(
File "/usr/lib/python3/dist-packages/compose/parallel.py", line 108, in parallel_execute
raise error_to_reraise
File "/usr/lib/python3/dist-packages/compose/parallel.py", line 206, in producer
result = func(obj)
File "/usr/lib/python3/dist-packages/compose/project.py", line 679, in do
return service.execute_convergence_plan(
File "/usr/lib/python3/dist-packages/compose/service.py", line 579, in execute_convergence_plan
return self._execute_convergence_recreate(
File "/usr/lib/python3/dist-packages/compose/service.py", line 499, in _execute_convergence_recreate
containers, errors = parallel_execute(
File "/usr/lib/python3/dist-packages/compose/parallel.py", line 108, in parallel_execute
raise error_to_reraise
File "/usr/lib/python3/dist-packages/compose/parallel.py", line 206, in producer
result = func(obj)
File "/usr/lib/python3/dist-packages/compose/service.py", line 494, in recreate
return self.recreate_container(
File "/usr/lib/python3/dist-packages/compose/service.py", line 612, in recreate_container
new_container = self.create_container(
File "/usr/lib/python3/dist-packages/compose/service.py", line 330, in create_container
container_options = self._get_container_create_options(
File "/usr/lib/python3/dist-packages/compose/service.py", line 921, in _get_container_create_options
container_options, override_options = self._build_container_volume_options(
File "/usr/lib/python3/dist-packages/compose/service.py", line 960, in _build_container_volume_options
binds, affinity = merge_volume_bindings(
File "/usr/lib/python3/dist-packages/compose/service.py", line 1548, in merge_volume_bindings
old_volumes, old_mounts = get_container_data_volumes(
File "/usr/lib/python3/dist-packages/compose/service.py", line 1579, in get_container_data_volumes
container.image_config['ContainerConfig'].get('Volumes') or {}
KeyError: 'ContainerConfig'
我可以使用以下命令手动启动容器:
sudo docker start <container_name>
重新启动 docker 服务并重新启动计算机均未解决问题。您知道此更新导致什么问题以及如何修复它吗?
答案1
我也是。将 改为 后,docker-compose
无需docker compose
进行其他更改即可正常工作。
现在,我的容器正在运行:
docker compose up -d
代替:
docker-compose up -d
这是因为docker-compose
V1 语法现已弃用。V2 语法是docker compose
,因为它现在是一个插件而不是一个单独的命令。
答案2
如果你像我一样通过 ansible 调用 docker-compose,那么你需要升级
社区.docker.docker_compose:
到
社区.docker.docker_compose_v2:
并可能进行一些其他更改,例如我必须将“pull:true”更改为“pull:always”
答案3
我今天遇到了同样的问题。
docker-compose down
它对我有用
答案4
有时你会因为正在运行容器而收到此错误。我曾经在使用 ansible playbook 时遇到过此错误,但这个方法对我有用。
- name: stopping existing container
shell:
chdir: "your path"
cmd: "docker-compose down"
- name: waiting 30 secondes to let the container stop
ansible.builtin.pause:
seconds: 30
- name: deploy Docker Compose stack
shell:
chdir: "your path"
cmd: "docker-compose build && docker-compose up -d"