Skip to content

Instantly share code, notes, and snippets.

@i-sync
Last active October 13, 2023 09:54
Show Gist options
  • Save i-sync/66b261b0d2dc8506b3859d3bfdd1b4c4 to your computer and use it in GitHub Desktop.
Save i-sync/66b261b0d2dc8506b3859d3bfdd1b4c4 to your computer and use it in GitHub Desktop.
docker-compose add proxy

How to add proxy to docker-compose.yml & Dockerfile

The proxy in my host machine.

example: https://10.0.0.1:8123

Update the docker-compose.yml

Add the extra_hosts

version: '3'
services:
    tabby:
        build: .
        restart: always
        depends_on:
        - db
        ports:
        - 9090:9090
        extra_hosts:
        - "host.docker.internal:10.0.0.1"
        volumes:
        - ./app-dist:/app-dist
Add the proxy env in Dockerfile
FROM node:12.16-alpine3.11

ENV NODE_ENV=development
#ENV http_proxy 'host.docker.internal:8123'
#ENV https_proxy 'host.docker.internal:8123'

#https://stackoverflow.com/a/52650320
ENV HTTP_PROXY  http://host.docker.internal:8123
ENV HTTPS_PROXY  http://host.docker.internal:8123

WORKDIR /usr/src/app

RUN apk update && apk upgrade && apk add --no-cache \
    bash git openssh python2 curl

RUN npm i -g webpack webpack-cli webpack-dev-server

COPY --chown=root:root package.json /home/node
COPY install.sh   /home/node
RUN  chmod +x     /home/node/install.sh
RUN  chmod +w     /home/node/package.json
CMD  ["/home/node/install.sh"]
test the proxy if work
...

RUN apk update && apk upgrade && apk add --no-cache \
    bash git openssh python2 curl
    
RUN ping -c 4 host.docker.internal

RUN curl -I https://www.google.com

...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment