配置好数据库,选择postgres13.4

version: '3' services:
postgres14.3:
container_name: "postgres14.3"
image: postgres:14.3
volumes:
- /workspace/docker_folder2/postgres14.3:/var/lib/postgresql/data
command: 'tail -F /dev/null'
# command: 'postgres'
ports:
- "5532:5432"
stdin_open: true
tty: true
environment:  #这些内容仅在第一次创建docker的时候有用
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=88888888

sudo docker-compose up

在运行docker连接数据库的过程,出现报错

postgres14.3    | 2022-06-02 02:30:31.317 UTC [89] FATAL:  password authentication failed for user "postgresql"
postgres14.3    | 2022-06-02 02:30:31.317 UTC [89] DETAIL:  Role "postgresql" does not exist.
postgres14.3    |     Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"
^CGracefully stopping... (press Ctrl+C again to force)
Stopping postgres14.3   ...
Killing postgres14.3    ... error

ERROR: for postgres14.3  Cannot kill container: c9d54c6d1198d0969692286d6a841a35c82425bd602a6e7d6538f50047e676c6: Container c9d54c6d1198d0969692286d6a841a35c82425bd602a6e7d6538f50047e676c6 is not running
ERROR: 2

首先使用命令export DOCKER_DEFAULT_PLATFORM=linux/amd64

然后执行sudo docker-compose up

会出现同样的报错,查看配置文件,进行command的注释,把command进行替换注释,就可以了

sudo docker-compose up
WARNING: Found orphan containers (test_rails_crud_db_1, test_rails_crud_web_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Recreating postgres14.3 ... done
Attaching to postgres14.3