docker-compose.yml
version: '2.1'
services:
vincent-db:
image: daocloud.io/library/postgres:10
volumes:
- ./data/postgres:/var/lib/postgresql/data
- ./init-db:/docker-entrypoint-initdb.d
environment:
POSTGRES_USER: vincent
POSTGRES_PASSWORD: 521314
POSTGRES_DB: vincent
ports:
- 5433:5433
expose:
- 5432
restart: always
启动 docker-compose
docker-compose up
docker pa -s # 查看容器
haha@haha-W330-H30:~$ docker ps -a
docker进入容器
docker exec -it <容器id> bash
进入 pgsql 容器
docker exec -it 5fc7956bc3f3 bash
haha@haha-W330-H30:~$ docker exec -it 5fc7956bc3f3 bash
root@5fc7956bc3f3:/# psql -U vincent
psql (10.16 (Debian 10.16-1.pgdg90+1))
Type "help" for help.
vincent=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges | |||||
---|---|---|---|---|---|---|---|---|---|---|
postgres | vincent | UTF8 | en_US.utf8 | en_US.utf8 | template0 | vincent | UTF8 | en_US.utf8 | en_US.utf8 | =c/vincent + |
| | | | | vincent=CTc/vincent
template1 | vincent | UTF8 | en_US.utf8 | en_US.utf8 | =c/vincent +
| | | | | vincent=CTc/vincent
vincent | vincent | UTF8 | en_US.utf8 | en_US.utf8 |
(5 rows)
vincent=#
查看容器的ip
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <容器id>
haha@haha-W330-H30:~$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 5fc7956bc3f3
172.23.0.2
NAVICAT 连接数据库