Most appropriate container for a data only container?

前端 未结 4 531
攒了一身酷
攒了一身酷 2021-02-05 02:33

What is the most appropriate (smallest, simplest) container to use for a data only Docker container?

In the documentation they use the training/postgres container. Howe

相关标签:
4条回答
  • 2021-02-05 03:17

    I recommend the tianon/true image from this collection of dockerfiles. At 125 Byte, It is smaller than busybox based images:

    REPOSITORY                 TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    tianon/true                latest              724d63a6172d        35 hours ago        125 B
    

    A container based on this image exits immediately which is appropriate for a storage only container.

    0 讨论(0)
  • 2021-02-05 03:20

    Update: Now that we have named volumes, you generally don't want to use data containers at all.

    Use the same image for the data container - in this case the Postgres image. You don't leave data containers running, so it won't consume resources.

    Using the same image is important for several reasons:

    • It will take up less space as you already have the image cached.
    • The image gets a chance to seed the volume with data e.g. default files.
    • The permissions and owner will be correct.

    For more information see Data Only Container Madness.

    0 讨论(0)
  • 2021-02-05 03:25

    Busybox is a base image, not a user image, and thus a little more practical for production use, it is also tiny.

    The image docker page here

    BusyBox: The Swiss Army Knife of Embedded Linux

    At about 2.5 Mb in size. Busybox is one of the smallest Linux distribution available.

    BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts. BusyBox provides a fairly complete environment for any small or embedded system.

    0 讨论(0)
  • 2021-02-05 03:32

    This post recommends using an empty "scratch" container - no OS at all:

    Dockerfile:

    FROM scratch
    
    VOLUME /data
    ENTRYPOINT ["/no/such/file"]
    

    I just made an empty one, and the image is... 0 bytes!

    Then I COPY'd just a 2k file in during build, and the image is 260 bytes, so must be compressed.

    I am using this because named volumes aren't so useful in semi/serverless environments like AWS Fargate where is no host, and you want to deploy versioned data.

    Update: if you want the container to work correctly in docker-compose the above example won't work because the entrypoint fails. tianon/true seems to be the best solution, a tiny program which returns true. So you can use FROM tianon/true.

    0 讨论(0)
提交回复
热议问题