一、问题
docker启动postgresql数据库报错
启动命令
docker run --name postgres -e POSTGRES_PASSWORD=123456 -p 5432:5432 -d postgres:9.6
日志
docker: Error response from daemon: Conflict. The container name "/postgres" is already in use by container "5305e20894e37b4ee2ebf7bc98847e99cb8b37b4691234568a94fa51e3fbd905". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
二、解决
查看所有进程
C:\Users\username>docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5305e20894e3 postgres:9.6 "docker-entrypoint.s…" 24 minutes ago Exited (0) 3 minutes ago postgres
发现之前运行的还没有正常退出,导致出现了容器重名的情况,
复制上面出现的id删除即可
C:\Users\username>docker rm 5305e20894e3
5305e20894e3
再运行启动命令,已经可以正常启动了
C:\Users\username>docker run --name postgres -e POSTGRES_PASSWORD=123456 -p 5432:5432 -d postgres:9.6
ef83495f5037f02bf413a35b8955c514dc927f40dccb0f3617853fe7aa94192f
查看所有进程,发现status已经是启动状态了
C:\Users\username>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ef83495f5037 postgres:9.6 "docker-entrypoint.s…" 13 seconds ago Up 11 seconds 0.0.0.0:5432->5432/tcp postgres
用DBeaver连接也已经可以连上了