Per per utilizzare un proxy all’interno della procedura di build prevista nel Dockerfile impostato dal compose.yaml è necessario effettuare sia una modifica al compose.yaml che al Dockerfile.
Nel mio esempio il proxy è attivo sulla macchina host, pertanto lo si può “puntare” con il nome host.docker.internal avendo l’accortezza di aggiungere, come vedremo in avanti, nel file compose.yaml:
extra_hosts:
- "host.docker.internal:host-gateway"
Ipotizziamo che il Dockerfile contenga qualcosa di questo tipo:
# Stage 1: Dipendenze
FROM node:20-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
dobbiamo aggiungere le necessarie variabili facendolo diventare:
# Stage 1: Dipendenze
FROM node:20-alpine AS deps
ARG HTTP_PROXY
ARG HTTPS_PROXY
ARG NO_PROXY
ENV HTTP_PROXY=${HTTP_PROXY}
ENV HTTPS_PROXY=${HTTPS_PROXY}
ENV NO_PROXY=${NO_PROXY}
RUN apk add --no-cache libc6-compat
WORKDIR /app
ora passiamo a modificare il compose.yaml che da:
services:
app:
image: gest:latest
build:
context: .
dockerfile: Dockerfile
args:
BUILD_GIT_SHA: ${BUILD_GIT_SHA:-unknown}
BUILD_DATE: ${BUILD_DATE:-unknown}
container_name: app-club
restart: unless-stopped
dovrà diventare:
services:
app:
image: gest:latest
build:
context: .
dockerfile: Dockerfile
args:
BUILD_GIT_SHA: ${BUILD_GIT_SHA:-unknown}
BUILD_DATE: ${BUILD_DATE:-unknown}
HTTP_PROXY: http://host.docker.internal:8888
HTTPS_PROXY: http://host.docker.internal:8888
NO_PROXY: 127.0.0.1,localhost
extra_hosts:
- "host.docker.internal:host-gateway"
container_name: app-club
restart: unless-stopped
enjoy!
Ti interessa acquistare un dominio a prezzi ultraconvenienti? clicca qui
Se hai trovato utili le informazioni su questo blog,
Fai una donazione!
Clicca sul bottone qui sotto o almeno clicca sul banner pubblicitario 🙂
Commenta