# Using proxy in Dockerfile

**URL:** <https://forums.docker.com/t/using-proxy-in-dockerfile/140910>\
**Category:** Compose\
**Created:** [April 17, 2024, 7:41pm UTC](https://forums.docker.com/t/using-proxy-in-dockerfile/140910 "2024-04-17T19:41:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hack3rcon](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/hack3rcon/32/50683_2.png) [@hack3rcon](https://forums.docker.com/u/hack3rcon)\
**Post date:** [April 17, 2024, 7:41pm UTC](https://forums.docker.com/t/using-proxy-in-dockerfile/140910/1 "2024-04-17T19:41:08Z")

</div>

Hello,  
I have a Dockerfile like below:

```auto
FROM node:14-alpine
WORKDIR /usr/src/app

COPY package*.json /usr/src/app/
RUN npm install

COPY . /usr/src/app

ENV PORT 5000
EXPOSE $PORT
CMD ["npm", "start"]

```

I have a SOCKS5 proxy on the host and I want the `RUN npm install` command to download files through this proxy. Is this possible?

Thank you.

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/bluepuma77/32/32688_2.png) [@bluepuma77](https://forums.docker.com/u/bluepuma77)\
**Post date:** [April 18, 2024, 6:40am UTC](https://forums.docker.com/t/using-proxy-in-dockerfile/140910/2 "2024-04-18T06:40:33Z")

</div>

As I have already seen some posts from you here on the forum, I get the impression you are a little bit careless. It seems you are copy-pasting a lot of config pieces from the Internet (Stackoverflow?), without actually understanding and checking.

Please be aware that node 14 is end of life since last year. Please make sure you always run latest versions to avoid running any containers with open security issues. You don’t want any malicious actor taking over your server.

* * *

`npm` does not seem to support socks proxy, see [issue](https://github.com/npm/npm/issues/6204). There are some workarounds discussed.

Alternatively you might try to configure Docker to use a proxy, see [docs](https://docs.docker.com/network/proxy/).

---

<div class="post-metadata">

**Author:** ![hack3rcon](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/hack3rcon/32/50683_2.png) [@hack3rcon](https://forums.docker.com/u/hack3rcon)\
**Post date:** [April 19, 2024, 2:03pm UTC](https://forums.docker.com/t/using-proxy-in-dockerfile/140910/3 "2024-04-19T14:03:18Z")

</div>

Hello,  
Thank you so much for your reply.  
No, I didn’t copy this `Dockerfile` from somewhere. When you create a project on the GitLab server from the templates, this file is generated.  
Socksify tool? Can Proxychains be used?

I have added the following lines to the `/lib/systemd/system/docker.service` file for pulling images:

```auto
[Service]
Environment="HTTP_PROXY=socks5://127.0.0.1:<PROXY_PORT>"
Environment="HTTPS_PROXY=socks5://127.0.0.1:<PROXY_PORT>"
Replace 

```

But it doesn’t work for `Dockerfile`.

---

<div class="post-metadata">

**Author:** ![mgvazquez](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/mgvazquez/32/40962_2.png) [@mgvazquez](https://forums.docker.com/u/mgvazquez)\
**Post date:** [April 20, 2024, 3:35pm UTC](https://forums.docker.com/t/using-proxy-in-dockerfile/140910/4 "2024-04-20T15:35:44Z")

</div>

As @bluepuma77 said, Docker supports the use of proxies for building images (see [docs](https://docs.docker.com/network/proxy/)).  
What does not appear in the documentation, is that it is possible to clarify the proxy protocol.

For example: in the documentation it shows the following:

```auto
~/.docker/config.json.
{
 "proxies": {
   "default": {
     "httpProxy": "http://proxy.example.com:3128",
     "httpsProxy": "https://proxy.example.com:3129",
     "noProxy": "*.test.example.com,.example.org,127.0.0.0.0/8"
   }
 }
}

```

You can change the protocol to use socks:

```auto
{
 "proxies": {
   "default": {
     "httpProxy": "socks5h://proxy.example.com:3128",
     "httpsProxy": "socks5h://proxy.example.com:3129",
     "noProxy": "*.test.example.com,.example.org,127.0.0.0.0/8"
   }
 }
}

```

StackOverflow: [Use socks5 proxy from host for docker build - Stack Overflow](https://stackoverflow.com/questions/61590317/use-socks5-proxy-from-host-for-docker-build)

---

<div class="post-metadata">

**Author:** ![hack3rcon](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/hack3rcon/32/50683_2.png) [@hack3rcon](https://forums.docker.com/u/hack3rcon)\
**Post date:** [April 21, 2024, 6:49pm UTC](https://forums.docker.com/t/using-proxy-in-dockerfile/140910/5 "2024-04-21T18:49:54Z")

</div>

Hi,  
Thank you so much for your reply.  
After this, does the `RUN npm install` command use a proxy to receive files?

---

<div class="post-metadata">

**Author:** ![hack3rcon](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/hack3rcon/32/50683_2.png) [@hack3rcon](https://forums.docker.com/u/hack3rcon)\
**Post date:** [April 25, 2024, 9:59am UTC](https://forums.docker.com/t/using-proxy-in-dockerfile/140910/6 "2024-04-25T09:59:13Z")

</div>

Hello,  
In my system, the proxy is running on the address `127.0.0.1:9050`. Why is Docker’s IP address used in [this](https://stackoverflow.com/questions/61590317/use-socks5-proxy-from-host-for-docker-build) example?

Thank you.

---

<div class="post-metadata">

**Author:** ![hack3rcon](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/hack3rcon/32/50683_2.png) [@hack3rcon](https://forums.docker.com/u/hack3rcon)\
**Post date:** [April 27, 2024, 1:56pm UTC](https://forums.docker.com/t/using-proxy-in-dockerfile/140910/7 "2024-04-27T13:56:55Z")

</div>

Hello,  
I did the following:

```auto
{
        "proxies":
        {
            "default":
            {
                "httpProxy": "socks5h://127.0.0.1:<PROXY_PORT>",
                "httpsProxy": "socks5h://127.0.0.1:<PROXY_PORT>",
                "noProxy": ""
            }
        }
    }

```

And:

```auto
"httpProxy": "socks5h://172.16.0.1:<PROXY_PORT>"

```

None of them worked properly!
