Avoid container image from exiting in net aspire

I am using builder.AddPostgres().WithImage(...) but the image has this behaviour of exiting if I don’t use -it when doing docker run

this is the way the documentation says to use this image:

docker run 
    -it 
    -v postgresml_data:/var/lib/postgresql 
    -p 5433:5432 
    -p 8000:8000 
    ghcr.io/postgresml/postgresml:2.7.12 
    sudo -u postgresml psql -d postgresml

this is how I add postgres but does not seed to work, the item is show in the dashboard as exited and in docker if I press the play button it just start and exit in less than a minute, which is the correct way to keep the container running.

    postgres = builder.AddPostgres("lcommerce-dependecy-postgres", port: 5432)
        .WithImage("postgresml/postgresml")
        .WithImageTag("2.9.3")
        .WithImageRegistry("ghcr.io")
        .WithHttpEndpoint(name: "endpoint-55432-5432",
            port: 8000, targetPort: 8000, isProxied: true)
        .WithContainerRuntimeArgs("-it", "--gpus=all");

I tried to keep the container running using .WithContainerRuntimeArgs("-it", "--gpus=all") but keep exiting. (by default net aspire adds postgres user and password I already tested another image pgvector/pgvector and it works fine but this one does no exit by default)

UPDATE

YOU CAN USE

.WithContainerRuntimeArgs("-i", "--gpus=all")
.WithArgs("sudo", "-u", "postgresml", "psql", "-d", "postgresml")

BUT BEST IS

(as the answer suggest):

.WithContainerRuntimeArgs("--gpus=all")
.WithArgs( "sleep","infinity")

THE CORRECT IS

Create a custom image with the extension and needed modules and set the database server as the main persistent process instead of using a workaround (as the answer mentioned)

2

That image’s Dockerfile is publicly available. It has a couple of significant design issues. Most notably, it does not run the database server as the main container process, but instead depends on some other process running to “keep the container alive”, something you should never need to actually do. A typical hackaround for this is to run a meaningless sleep command. This probably looks something like

postgres = builder.AddPostgres("lcommerce-dependecy-postgres", port: 5432)
  .WithArgs("sleep", "infinity")
  ...;

What’s happening internally? The image declares

ENTRYPOINT ["bash", "/app/entrypoint.sh"]

(typically you should just run script, not bash script) without a default CMD. The entrypoint.sh calls service postgresql start (service doesn’t usually work in Docker and a container normally only runs one process), runs several sudo -u postgresml commands (sudo is hard to use and is almost always unnecessary in Docker) and finally ends with

exec "$@"

Docker passes the CMD as arguments to the ENTRYPOINT, but in the default setup CMD is empty. That runs exec with no arguments, which does nothing, and the script exits. Since the script is the main container process, when the script exits, the container exits too.

The Docker Hub postgres image page points at the PostGIS image as a more typical way of building a PostgreSQL image plus an extension. Download the extension proper (the PostgresML Dockerfile uses APT to get it, which should be just fine), put the relevant SQL CREATE EXTENSION commands into a script in /docker-entrypoint-initdb.d, and let the normal first-time initialization set up the extension. For this particular extension you’d need to add CUDA on top of a PostgreSQL image rather than vice versa, but the standard database image setup is kind of involved and it could be better to reuse it.

6

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật