Docker磁盘空间问题,主机

时间:2017-11-14 15:07:04

标签: postgresql docker

我在Docker容器中运行PostgreSQL(OS X 10.11.6上的Docker 17.09.0-ce-mac35),并且我在主机上的Python应用程序中插入数据。过了一会儿,我在Python中始终遇到以下错误,而主机上仍有足够的磁盘空间:

psycopg2.OperationalError: could not extend file "base/16385/24599.49": wrote only 4096 of 8192 bytes at block 6543502
HINT:  Check free disk space.

这是我的docker-compose.yml

version: "2"

services:

  rabbitmq:
    container_name: rabbitmq
    build: ../messaging/
    ports:
      - "4369:4369"
      - "5672:5672"
      - "25672:25672"
      - "15672:15672"
      - "5671:5671"

  database:
    container_name: database
    build: ../database/
    ports:
      - "5432:5432"

数据库Dockerfile如下所示:

FROM ubuntu:17.04

RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ zesty-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN apt-get update && apt-get install -y --allow-unauthenticated python-software-properties software-properties-common postgresql-10 postgresql-client-10 postgresql-contrib-10

USER postgres

RUN /etc/init.d/postgresql start &&\
    psql --command "CREATE USER ****** WITH SUPERUSER PASSWORD '******';" &&\
    createdb -O ****** ******

RUN echo "host all  all    0.0.0.0/0  md5" >> /etc/postgresql/10/main/pg_hba.conf
RUN echo "listen_addresses='*'" >> /etc/postgresql/10/main/postgresql.conf

EXPOSE 5432

VOLUME  ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]

CMD ["/usr/lib/postgresql/10/bin/postgres", "-D", "/var/lib/postgresql/10/main", "-c", "config_file=/etc/postgresql/10/main/postgresql.conf"]

df -k输出:

Filesystem    1024-blocks      Used Available Capacity   iused     ifree %iused  Mounted on
/dev/disk2     1088358016 414085004 674017012    39% 103585249 168504253   38%   /
devfs                 190       190         0   100%       658         0  100%   /dev
map -hosts              0         0         0   100%         0         0  100%   /net
map auto_home           0         0         0   100%         0         0  100%   /home

更新1:

似乎容器现已关闭。在重新关闭之前,我将重新开始尝试df -k容器。

2017-11-14 14:48:25.117 UTC [18] HINT:  In a moment you should be able to reconnect to the database and repeat your command.
2017-11-14 14:48:25.120 UTC [17] WARNING:  terminating connection because of crash of another server process
2017-11-14 14:48:25.120 UTC [17] DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2017-11-14 14:48:25.120 UTC [17] HINT:  In a moment you should be able to reconnect to the database and repeat your command.
2017-11-14 14:48:25.132 UTC [1] LOG:  all server processes terminated; reinitializing
2017-11-14 14:48:25.175 UTC [1] FATAL:  could not access status of transaction 0
2017-11-14 14:48:25.175 UTC [1] DETAIL:  Could not write to file "pg_notify/0000" at offset 0: No space left on device.
2017-11-14 14:48:25.181 UTC [1] LOG:  database system is shut down

更新2:

容器上的df -k/dev/vda2似乎很快就会填满:

$ docker exec -it database df -k
Filesystem     1K-blocks     Used Available Use% Mounted on
none            61890340 15022448  43700968  26% /
tmpfs              65536        0     65536   0% /dev
tmpfs            1023516        0   1023516   0% /sys/fs/cgroup
/dev/vda2       61890340 15022448  43700968  26% /etc/postgresql
shm                65536        8     65528   1% /dev/shm
tmpfs            1023516        0   1023516   0% /sys/firmware

更新3:

这似乎与Docker.qcow2的~64 GB文件大小限制有关。解决使用qemu和gparted如下:

cd ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/
qemu-img info Docker.qcow2
qemu-img resize Docker.qcow2 +200G
qemu-img info Docker.qcow2
qemu-system-x86_64 -drive file=Docker.qcow2  -m 512 -cdrom ~/Downloads/gparted-live-0.30.0-1-i686.iso -boot d -device usb-mouse -usb 

0 个答案:

没有答案