我使用 virtualbox 在 ubuntu vm 上安装了 postgres,主机是 windows 10
umen@umen:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2583c47b9879 postgres:14.5 "docker-entrypoint.s…" 27 minutes ago Up 16 minutes 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp umen-postgres-1
网络:umen@umen:~$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:d2:b3:90 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 metric 100 brd 10.0.2.255 scope global dynamic enp0s3
valid_lft 84940sec preferred_lft 84940sec
inet6 fe80::a00:27ff:fed2:b390/64 scope link
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:0b:76:ab:40 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
4: br-fb9123c510ce: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:b3:7c:dd:85 brd ff:ff:ff:ff:ff:ff
inet 172.18.0.1/16 brd 172.18.255.255 scope global br-fb9123c510ce
valid_lft forever preferred_lft forever
inet6 fe80::42:b3ff:fe7c:dd85/64 scope link
valid_lft forever preferred_lft forever
6: veth24b752d@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-fb9123c510ce state UP group default
link/ether 22:61:bb:76:68:83 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::2061:bbff:fe76:6883/64 scope link
valid_lft forever preferred_lft forever
docker-compose.yml
version: '3'
services:
postgres:
image: 'postgres:14.5'
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: movies
logging:
options:
max-size: 10m
max-file: "3"
ports:
- '5432:5432'
volumes:
- ./postgres-data:/var/lib/postgresql/data
- ./sql/create_tables.sql:/docker-entrypoint-initdb.d/create_tables.sql