hf-llm-api / Dockerfile
Pyboxs's picture
Update Dockerfile
1088f52 verified
# Filename: Dockerfile
# Version: $(date +%s)
FROM alpine:latest
# Instalar dependencias necesarias
RUN apk add --no-cache \
docker \
docker-cli \
shadow \
sudo \
curl \
iptables \
nginx \
fuse-overlayfs \
shadow-uidmap
# Crear un usuario no root
RUN adduser -D -g '' dockeruser && echo "dockeruser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
# Cambiar al usuario no root
USER dockeruser
# Configurar Docker rootless manualmente
RUN curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-rootless-extras-20.10.7.tgz | tar -xz -C ~/
RUN ~/docker-rootless-extras/install
RUN echo 'export PATH=$HOME/bin:$PATH' >> /home/dockeruser/.profile
RUN echo 'export DOCKER_HOST=unix:///run/user/1000/docker.sock' >> /home/dockeruser/.profile
# Crear el archivo de servicio para Docker rootless
RUN mkdir -p /home/dockeruser/.config/systemd/user/ && \
echo '[Unit]\n\
Description=Docker Application Container Engine (Rootless)\n\
Documentation=https://docs.docker.com/go/rootless/\n\
Wants=network-online.target\n\
After=network-online.target firewalld.service containerd.service\n\
StartLimitIntervalSec=0\n\
\n\
[Service]\n\
Environment="PATH=/usr/bin:/usr/sbin"\n\
ExecStart=/home/dockeruser/bin/dockerd-rootless.sh --experimental --host=tcp://0.0.0.0:7680\n\
Restart=always\n\
User=dockeruser\n\
LimitNOFILE=infinity\n\
LimitNPROC=infinity\n\
LimitCORE=infinity\n\
Delegate=yes\n\
KillMode=process\n\
\n\
[Install]\n\
WantedBy=default.target' > /home/dockeruser/.config/systemd/user/docker.service
# Cambiar al usuario root para configurar Nginx
USER root
# Configurar Nginx
RUN echo 'server {\n\
listen 80;\n\
location /docker {\n\
proxy_pass http://localhost:7680;\n\
proxy_set_header Host $host;\n\
proxy_set_header X-Real-IP $remote_addr;\n\
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
proxy_set_header X-Forwarded-Proto $scheme;\n\
}\n\
location / {\n\
return 200 "Hello World";\n\
add_header Content-Type text/plain;\n\
}\n\
}' > /etc/nginx/conf.d/default.conf
# Exponer el puerto para la API de Docker y Nginx
EXPOSE 80
EXPOSE 7680
# Configurar el comando de inicio
CMD ["sh", "-c", "~/.docker-rootless-extras/docker-rootless.sh --experimental --host=tcp://0.0.0.0:7680 & nginx -g 'daemon off;'"]