Docker - Wie kann der Befehl psql im Postgres-Container ausgeführt werden?

Ich möchte das psql im postgres-Bild verwenden, um einige Abfragen in der Datenbank auszuführen. Aber leider, wenn ich an den Postgres-Container anhänge, erhalte ich den Fehler, dass der Befehl psql nicht gefunden wird ...

Für mich ist es ein Rätsel, wie ich postgre SQL-Abfragen oder -Befehle im Container ausführen kann.

Wie führe ich den Befehl psql im Postgres-Container aus? (Ich bin ein neuer Typ in der Docker-Welt)

Ich verwende Ubuntu als Host-Computer und habe das Postgres nicht auf dem Host-Computer installiert. Ich verwende stattdessen den Postgres-Container.

docker-compose ps
        Name                       Command               State               Ports            
---------------------------------------------------------------------------------------------
yiialkalmi_app_1        /bin/bash                        Exit 0                               
yiialkalmi_nginx_1      nginx -g daemon off;             Up       443/tcp, 0.0.0.0:80->80/tcp 
yiialkalmi_php_1        php-fpm                          Up       9000/tcp                    
yiialkalmi_postgres_1   /docker-entrypoint.sh postgres   Up       5432/tcp                    
yiialkalmi_redis_1      docker-entrypoint.sh redis ...   Up       6379/tcp     

Hier die Container:

docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                         NAMES
315567db2dff        yiialkalmi_nginx    "nginx -g 'daemon off"   18 hours ago        Up 3 hours          0.0.0.0:80->80/tcp, 443/tcp   yiialkalmi_nginx_1
53577722df71        yiialkalmi_php      "php-fpm"                18 hours ago        Up 3 hours          9000/tcp                      yiialkalmi_php_1
40e39bd0329a        postgres:latest     "/docker-entrypoint.s"   18 hours ago        Up 3 hours          5432/tcp                      yiialkalmi_postgres_1
5cc47477b72d        redis:latest        "docker-entrypoint.sh"   19 hours ago        Up 3 hours          6379/tcp                      yiialkalmi_redis_1

Und das ist meine docker-compose.yml:

app:
image: ubuntu:16.04
volumes:
    - .:/var/www/html

nginx:
    build: ./docker/nginx/
    ports:
        - 80:80
    links:
        - php
    volumes_from:
        - app
    volumes:
        - ./docker/nginx/conf.d:/etc/nginx/conf.d

php:
    build: ./docker/php/
    expose:
        - 9000
    links:
        - postgres
        - redis
    volumes_from:
        - app

postgres:
    image: postgres:latest
    volumes:
        - /var/lib/postgres
    environment:
        POSTGRES_DB: project
        POSTGRES_USER: project
        POSTGRES_PASSWORD: project

redis:
    image: redis:latest
    expose:
        - 6379

Antworten auf die Frage(8)

Ihre Antwort auf die Frage