ubuntu@center-kitchen:/data/postsql-redis$ sudo docker exec -it 1676ca9b2eb9 psql -U postgres -d postgres psql: FATAL: role "postgres" does not exist
使用docker-compose.yml创建postgresSQL,登录psql容器时提示缺少postgres角色:
ubuntu@center-kitchen:/data/postsql-redis$ sudo docker exec -it 1676ca9b2eb9 psql -U postgres -d postgres
psql: FATAL: role "postgres" does not exist
排查了很久,查看了官方文档,找到了问题,缺个参数:privileged: true(红色字体所示),贴上我的yml文件:
version: '2.3'
networks:
ic_net:
name: ic_net
ipam:
driver: default
config:
- subnet: "172.20.0.0/24"
services:
redis:
image: redis:4
restart: always
container_name: pigfarm_redis
ports:
- 6379:6379
logging:
driver: "json-file"
options:
max-size: "100m"
networks:
- ic_net
postgres:
image: postgres:9.6
restart: always
container_name: pigfarm_postgres
ports:
- 5432:5432
privileged: true
environment:
POSTGRES_PASSWORD: postgres
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- ./pg_data/data:/var/lib/postgresql/data/pgdata
logging:
driver: "json-file"
networks:
- ic_net
ubuntu@center-kitchen:/data/postsql-redis$ sudo docker-compose down
ubuntu@center-kitchen:/data/postsql-redis$ sudo docker-compose up -d
重启后,登录验证,成功进入数据库,如下所示:
ubuntu@center-kitchen:/data/postsql-redis$ sudo docker exec -it bd04bb35f624 psql -U postgres -d postgres
psql (9.6.17)
Type "help" for help.
postgres=#
结束。