docker-compose - Docker compose 无法运行命令服务未运行
问题描述
我创建了 docker-compose.yml,您可以在下面找到这些内容。我导航到文件抵抗并运行命令的文件夹:
docker-compose up -d
这表明:
Starting postgres ... done
然后我运行该查询:
docker-compose ps
结果:
Name Command State Ports
---------------------------------------------------------
postgres docker-entrypoint.sh postgres Exit 1
现在我想运行一些命令:
docker exec -it postgres psql -h localhost -p 54320 -U robert
这就是我得到的:
Error response from daemon: Container ae1565a84bcf0b3662b47d4f277efd2830273554b6bcf4437129e33b31c88b35 is not running
我的容器没有运行吗?请支持。码头工人-compose.yml:
version: "3"
services:
# Create a service named db.
db:
# Use the Docker Image postgres. This will pull the newest release.
image: "postgres"
# Give the container the name my_postgres. You can changes to something else.
container_name: "postgres"
# Setup the username, password, and database name. You can changes these values.
environment:
- POSTGRES_USER=robert
- POSTGRES_PASSWORD=robert
- POSTGRES_DB=mydb
# Maps port 54320 (localhost) to port 5432 on the container. You can change the ports to fix your needs.
ports:
- "54320:5432"
# Set a volume some that database is not lost after shutting down the container.
# I used the name postgres-data but you can changed it to something else.
volumes:
- ./volumes/postgres:/var/lib/postgresql/data
解决方案
你可以尝试执行吗
docker run -it postgres psql -h localhost -p 54320 -U robert
?
$ docker exec --help
用法:docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
在正在运行的容器中运行命令
由于您的容器具有状态退出,因此您不能使用 docker exec
推荐阅读
- java - Swagger UI 抱怨 ServerHttpRequest
- python-3.x - 每次在 PyQt5 中单击按钮时都会发生不同的事件
- python - python - 我希望多个线程产生多个进程,所有进程都应该并行运行
- gitlab-ci - 在 GitLab CI 中,有没有办法在合并请求中定义管道变量?
- android - Android Studio - 如何关闭“单词'word'中的错字?
- python - Matplotlib 从 CSV 中读取时间值
- excel - 如何将计算数据(每月平均)从源工作簿传输到我的主工作簿?
- python - 在 virtualenv 中禁用系统范围 (pip) 包
- c# - Wpf MVVM将ListView绑定到DataContext以外的数据
- regex - Python正则表达式解密