The LISTENER environment variable isn't working with Docker. #112

Closed
opened 2026-01-19 18:29:00 +00:00 by michael · 10 comments
Owner

Originally created by @flavorgold1 on GitHub.

It's stuck on port 8080.

How do I change this?

Originally created by @flavorgold1 on GitHub. It's stuck on port 8080. How do I change this?
Author
Owner

@stefanbenten commented on GitHub:

We could make it so that the binary per default listens on 8080 without specifying the flag at all, right?
Then setting the env variable should help, or one needs to pass this flag to the run command. Certainly better than having to maintain custom script solutions.

@stefanbenten commented on GitHub: We could make it so that the binary per default listens on 8080 without specifying the flag at all, right? Then setting the env variable should help, or one needs to pass this flag to the run command. Certainly better than having to maintain custom script solutions.
Author
Owner

@paolafrancesca commented on GitHub:

I was aware of the hardcoded listener value before in the Dockerfile and not so happy about it but I didn't want to remove since it could break a lot of docker deployment

Not sure if this is supported in docker, but could be a solution:
ENTRYPOINT ["/go/bin/transfersh", "--listener", "${LISTENER:-8080}"]

I've spent some time testing, it is not supported

the workaround will be to do something like:
ENTRYPOINT ["/go/bin/transfersh", "--listener", "${DOCKER_LISTENER:-8080}"]
and we have to replace this:
https://github.com/dutchcoders/transfer.sh/blob/main/server/server.go#L96
with
srvr.ListenerString = os.ExpandEnv(s)

the problem is that os.ExpandEnv() doesn't support as well the env notation used in the entrypoint
so we would have to write our own env expansion function, I'm not sure we want to go down that road: I tried a sample one calling echo on the shell, but we have no echo since the image is based on scratch

@paolafrancesca commented on GitHub: I was aware of the hardcoded listener value before in the `Dockerfile` and not so happy about it but I didn't want to remove since it could break a lot of docker deployment Not sure if this is supported in docker, but could be a solution: `ENTRYPOINT ["/go/bin/transfersh", "--listener", "${LISTENER:-8080}"]` I've spent some time testing, it is not supported the workaround will be to do something like: `ENTRYPOINT ["/go/bin/transfersh", "--listener", "${DOCKER_LISTENER:-8080}"]` and we have to replace this: https://github.com/dutchcoders/transfer.sh/blob/main/server/server.go#L96 with `srvr.ListenerString = os.ExpandEnv(s)` the problem is that `os.ExpandEnv()` doesn't support as well the env notation used in the entrypoint so we would have to write our own env expansion function, I'm not sure we want to go down that road: I tried a sample one calling `echo` on the shell, but we have no `echo` since the image is based on scratch
Author
Owner

@flavorgold1 commented on GitHub:

I understand that but, I'm in a situation where I have to use network_mode: host in docker-compose.yml. So, if there's a way through which it can respect that environment variable, it'd be great. Thanks anyways.

@flavorgold1 commented on GitHub: I understand that but, I'm in a situation where I have to use `network_mode: host` in `docker-compose.yml`. So, if there's a way through which it can respect that `environment variable`, it'd be great. Thanks anyways.
Author
Owner

@stefanbenten commented on GitHub:

@aspacca I would like your opinion on this.

@stefanbenten commented on GitHub: @aspacca I would like your opinion on this.
Author
Owner

@stefanbenten commented on GitHub:

Hello @flavorgold1,

the port is fixed inside of the container, see here:
b30b296ac8/Dockerfile (L38)

In order to map it to a different port you should probably use the docker networking features like this:
docker run -p 8081:8080 dutchcoders/transfer.sh:latest

@stefanbenten commented on GitHub: Hello @flavorgold1, the port is fixed inside of the container, see here: https://github.com/dutchcoders/transfer.sh/blob/b30b296ac838c73a4bcb83e394e6d9dac1b75e27/Dockerfile#L38 In order to map it to a different port you should probably use the docker networking features like this: `docker run -p 8081:8080 dutchcoders/transfer.sh:latest`
Author
Owner

@paolafrancesca commented on GitHub:

ENTRYPOINT ["/go/bin/transfersh"]
	cli.StringFlag{
		Name:   "listener",
		Usage:  "127.0.0.1:8080",
		Value:  ":8080",
		EnvVar: "LISTENER",
	},

these two changes fixes, only cons: users not specifing a --listener flag/LISTENER env variable will now bind on every interface instead of localhost only

if we keep Value: "127.0.0.1:8080", docker won't bind on every interface but only localhost, that's more disruptive probably

@paolafrancesca commented on GitHub: ``` ENTRYPOINT ["/go/bin/transfersh"] ``` ``` cli.StringFlag{ Name: "listener", Usage: "127.0.0.1:8080", Value: ":8080", EnvVar: "LISTENER", }, ``` these two changes fixes, only cons: users not specifing a `--listener` flag/`LISTENER` env variable will now bind on every interface instead of localhost only if we keep `Value: "127.0.0.1:8080"`, docker won't bind on every interface but only localhost, that's more disruptive probably
Author
Owner

@paolafrancesca commented on GitHub:

doh @flavorgold1
I did't think about the most obvious solution: overriding the entrypoint (either on docker-compose or with --entrypoint on docker run)

having /go/bin/transfersh as entrypoint should be enough if you specify a LISTENER env variable

@paolafrancesca commented on GitHub: doh @flavorgold1 I did't think about the most obvious solution: overriding the `entrypoint` (either on docker-compose or with ` --entrypoint` on docker run) having `/go/bin/transfersh` as entrypoint should be enough if you specify a `LISTENER` env variable
Author
Owner

@flavorgold1 commented on GitHub:

This may be a crude solution, but, here's my docker-compose.yml file. It is located in /home/username/transfersh_docker, along with a data directory located in that same directory. It works:

version: '3.7'
services:
  transfersh:
    container_name: transfersh
    image: dutchcoders/transfer.sh:latest
    restart: unless-stopped
    user: 1000:1000
    environment:
      - LISTENER=53749
      - BASEDIR=/tmp
      - PROXY_PATH=secretpath
      - PROVIDER=local
      - LOG=/tmp/transfersh.log
      - HTTP_AUTH_USER=username
      - HTTP_AUTH_PASS=password
      - PURGE_INTERVAL=0
      - RANDOM_TOKEN_LENGTH=14
      - MAX_UPLOAD_SIZE=40000000
    entrypoint: "/go/bin/transfersh --listener :53749"
    network_mode: "host"
    volumes:
      - /home/username/transfersh_docker/data:/tmp
@flavorgold1 commented on GitHub: This may be a crude solution, but, here's my `docker-compose.yml` file. It is located in `/home/username/transfersh_docker`, along with a `data` directory located in that same directory. It works: ``` version: '3.7' services: transfersh: container_name: transfersh image: dutchcoders/transfer.sh:latest restart: unless-stopped user: 1000:1000 environment: - LISTENER=53749 - BASEDIR=/tmp - PROXY_PATH=secretpath - PROVIDER=local - LOG=/tmp/transfersh.log - HTTP_AUTH_USER=username - HTTP_AUTH_PASS=password - PURGE_INTERVAL=0 - RANDOM_TOKEN_LENGTH=14 - MAX_UPLOAD_SIZE=40000000 entrypoint: "/go/bin/transfersh --listener :53749" network_mode: "host" volumes: - /home/username/transfersh_docker/data:/tmp ```
Author
Owner

@paolafrancesca commented on GitHub:

I will close this since it's solved

@paolafrancesca commented on GitHub: I will close this since it's solved
Author
Owner

@flavorgold1 commented on GitHub:

b30b296ac8/Dockerfile (L38)

if we keep Value: "127.0.0.1:8080", docker won't bind on every interface but only localhost, that's more disruptive probably

The way it is right now, it allows me to access the service via IPv4 and IPv6 directly, with network_mode: host. That's a good thing. Please preserve that functionality.

@flavorgold1 commented on GitHub: > https://github.com/dutchcoders/transfer.sh/blob/b30b296ac838c73a4bcb83e394e6d9dac1b75e27/Dockerfile#L38 > if we keep `Value: "127.0.0.1:8080"`, docker won't bind on every interface but only localhost, that's more disruptive probably The way it is right now, it allows me to access the service via IPv4 and IPv6 directly, with `network_mode: host`. That's a good thing. Please preserve that functionality.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dutchcoders/transfer.sh#112