Docker compose Docker compose无法运行未运行的命令服务
我创建了docker-compose.yml,您可以在下面找到它的内容。我导航到文件抵制并运行命令的文件夹:Docker compose Docker compose无法运行未运行的命令服务,docker-compose,Docker Compose,我创建了docker-compose.yml,您可以在下面找到它的内容。我导航到文件抵制并运行命令的文件夹: docker-compose up -d 这表明: Starting postgres ... done 然后我运行该查询: docker-compose ps 结果: Name Command State Ports -------------------------------------------------
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
我的容器是否没有运行或关闭?请支持我。
docker-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]容器命令[ARG…]
在正在运行的容器中运行命令
由于容器的状态为“退出”,因此无法使用docker exec是否可以使用此docker compose文件
版本:“3”
卷数:
postgres_应用程序:~
服务:
#创建一个名为db的服务。
博士后:
图片:“博士后”
环境:
博士后用户:罗伯特
POSTGRES_密码:robert
博士后数据库:“mydb”
卷数:
-“postgres_应用程序:/var/lib/postgresql/data”
端口:
- "54320:5432"
重新启动:始终
这个命令docker compose exec postgres psql-U robert-d mydb
我希望这会有帮助
我在我的计算机上执行了这个文件
是的,我可以,但这不是docker compose提交的。@Henry docker compose run-T postgres psql-h Local Host-p 54320-U robertERROR:没有这样的服务:postgresexactly)))docker compose run-T db psql-h Local Host-p 54320-U robertdocker compose run-T db psql-h Local Host-p 54320-U robert