openspeedtest / Speed-Test

SpeedTest by OpenSpeedTest™ is a Free and Open-Source HTML5 Network Performance Estimation Tool Written in Vanilla Javascript and only uses built-in Web APIs like XMLHttpRequest (XHR), HTML, CSS, JS, & SVG. No Third-Party frameworks or libraries are Required. Started in 2011 and moved to OpenSpeedTest.com dedicated Project/Domain Name in 2013.
https://openspeedtest.com
MIT License
2.19k stars 207 forks source link

Can't use different port other than 3000 in docker #84

Closed MekayelAnik closed 1 year ago

MekayelAnik commented 1 year ago

If I use a different port other than 3000 it does not load on that port, rather it loads on 3000 port. Notes:

So, when I do so, the WebUI does not load on , rather loads on :3000

openspeedtest commented 1 year ago

post you docker compose

MekayelAnik commented 1 year ago
#### Container Specific Configs ####
services:
  speedtest:
      image: openspeedtest/latest:latest
      container_name: openspeedtest
      environment:
        - TZ=Asia/Dhaka
  #    volumes:
  #      -v /${PATH-TO-YOUR-OWN-SSL-CERTIFICATE}:/etc/ssl/
      ports:
        - 80:3000
        - 443:3001
      dns:
        - 1.1.1.1
        - 1.0.0.1
      restart: always
#### Network Specific Configs ####
      hostname: openspeedtest
      domainname: local
      mac_address: aa-ee-ae-dd-bb-cc
      networks:
        my-macvlan:
          ipv4_address: 192.168.1.123
#### Network Defination ####
networks:
  my-macvlan:
    name: my-macvlan
    driver: macvlan
    driver_opts:
      parent: eth0
    ipam:
      config:
        - subnet: "192.168.1.0"
          ip_range: "192.168.1.0/24"
          gateway: "192.168.1.1"

Further Note:

openspeedtest commented 1 year ago

List the Docker containers you are running. Check for other openspeedtest containers already running on port 3000. Run the docker whoami image with the same configuration and see if you can access the container. Once it is working fine with the whoami image, switch the image to openspeedtest If you run

    ports:
      - 80:3000
      - 443:3001

You cannot access it from port 3000. The cached page may load, but when you click Start, it will show a Network Error.

MekayelAnik commented 1 year ago

there is no other openspeedtest container running. And I have used Incognito mode so that no previous cache is served.

openspeedtest commented 1 year ago

Did you run whoami image instead of openspeedtest? I am trying to isolate the issue here.

openspeedtest commented 1 year ago

Or run hello-world image, to make sure everything else in your setup is working fine.

MekayelAnik commented 1 year ago

I have used "traefik/whoami" image. It returned:

Hostname: openspeedtest
IP: 127.0.0.1
IP: 192.168.1.123
RemoteAddr: 192.168.1.17:51767
GET / HTTP/1.1
Host: 192.168.1.123
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en
Cache-Control: max-age=0
Connection: keep-alive
Sec-Gpc: 1
Upgrade-Insecure-Requests: 1

Docker Compose in this case:

version: "3.9"

#### Container Specific Configs ####
services:
  speedtest:
      image: traefik/whoami:latest
#      image: openspeedtest/latest:latest
      container_name: openspeedtest
      environment:
        - TZ=Asia/Dhaka
  #    volumes:
  #      -v /${PATH-TO-YOUR-OWN-SSL-CERTIFICATE}:/etc/ssl/
      ports:
        - 80:3000
        - 443:3001
      dns:
        - 1.1.1.1
        - 1.0.0.1
      restart: always
#### Network Specific Configs ####
      hostname: openspeedtest
      domainname: local
      mac_address: aa-ee-ae-dd-bb-cc
      networks:
        macvlan-RasPi4B:
        my-macvlan:
          ipv4_address: 192.168.1.123
#### Network Defination ####
networks:
  my-macvlan:
    name: my-macvlan
    driver: macvlan
    driver_opts:
      parent: eth0
    ipam:
      config:
        - subnet: "192.168.1.0"
          ip_range: "192.168.1.0/24"
          gateway: "192.168.1.1"

Maybe this is due to MacVlan. The same problem happens in Uptime-Kuma, Adminer etc. But works fine in smokeping, unbound, pihole, pgadmin, whoami etc. Any Idea?

openspeedtest commented 1 year ago

Yea, I tested port 80 and 443 worked without any issue.

docker logs openspeedtest what is the output?

I don't know why it's not working on your setup. Maybe macvlan is the reason, but I don't have much knowledge in this area.

I Asked Bard! :)

version: "3.9"

#### Container Specific Configs ####
services:
  speedtest:
    image: traefik/whoami:latest
#    image: openspeedtest/latest:latest
    container_name: openspeedtest
    environment:
      - TZ=Asia/Dhaka
    #    volumes:
    #      -v /${PATH-TO-YOUR-OWN-SSL-CERTIFICATE}:/etc/ssl/
    ports:
      - 80:3000
      - 443:3001
    dns:
      - 1.1.1.1
      - 1.0.0.1
    restart: always

#### Network Specific Configs ####
    hostname: openspeedtest
    domainname: local
    mac_address: aa-ee-ae-dd-bb-cc
    networks:
      macvlan-RasPi4B:
      my-macvlan:
        ipv4_address: 192.168.1.123

#### Network Defination ####
networks:
  my-macvlan:
    name: my-macvlan
    driver: macvlan
    driver_opts:
      parent: eth0
    ipam:
      config:
        - subnet: "192.168.1.0"
          ip_range: "192.168.1.0/24"
          gateway: "192.168.1.1"

The line networks: macvlan-RasPi4B: was added to the services section to specify that the speedtest container should be connected to the macvlan-RasPi4B network. The line ipv4_address: 192.168.1.123 was added to the my-macvlan network definition to specify the IP address that the speedtest container should be assigned. The line driver_opts: parent: eth0 was added to the my-macvlan network definition to specify that the my-macvlan network should be bridged to the eth0 interface on the host machine.

MekayelAnik commented 1 year ago

I think it is due to macvlan, yesterday I searched and most probably macvlan doesn't support it. But if the container chooses a port through Env Variable, this should solve the problem. Can you please add an Environment variable which will be used to set webUI Port? Only this can solve the issue permanently in all cases. Maybe grant this as a feature request.

openspeedtest commented 1 year ago

If that would solve the issue, we can do that. Before that, can you please build the image and test this? If you can confirm that this is a solution, I will add the following environment variables.

FORCE_HTTP_PORT FORCE_HTTPS_PORT

MekayelAnik commented 1 year ago

How can I build the image? Have you pushed the change?

For referance, I have a image in docker hub named "mekayelanik/ispyagentdvr". If I set the port of the software to 80 internally, then I can access the UI on port 80 thus I am saying this.

Building a image will be a bit time consuming and cumbersome as I don't know internals of Openspeedtest also don't have the Dockerfile. If you publish a test image I could varify this and later you could just delete that test image.

openspeedtest commented 1 year ago

Docker file https://github.com/openspeedtest/Docker-Image/blob/main/Dockerfile https://github.com/openspeedtest/Docker-Image/blob/main/files/OpenSpeedTest-Server.conf Change 3000 to 80 and 3001 to 443 in both the file and the build. If you find this difficult, please wait. I will do it very soon. And send you the beta image link to test. Also we need to fix https://github.com/openspeedtest/Docker-Image/blob/main/files/entrypoint.sh

openspeedtest commented 1 year ago

try docker pull openspeedtest/beta:v1.9 CHANGE_CONTAINER_PORTS=True HTTP_PORT=80 HTTPS_PORT=443

openspeedtest commented 1 year ago

sudo docker run -e CHANGE_CONTAINER_PORTS=True -e HTTP_PORT=80 -e HTTPS_PORT=443 --restart=unless-stopped --name openspeedtest -d -p 80:80 -p 443:443 openspeedtest/beta:v1.9.3

openspeedtest commented 1 year ago

Worked on my Machine, But you may see [emerg] 15#15: bind() to 0.0.0.0:80 failed (13: Permission denied) nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

https://hub.docker.com/r/nginxinc/nginx-unprivileged Says The default NGINX listen port is now 8080 instead of 80 (this is no longer necessary as of Docker 20.03 but it's still required in other container runtimes). https://www.reddit.com/r/docker/comments/u56lym/nginx_non_privileged_image_can_still_listen_to/

MekayelAnik commented 1 year ago

Alhamdulillah, It WORKS!!!! Many many thanks for your great work and rapid action. Please release this in "latest" and please add these ENV variables in image documentation in Docker Hub. Great job. Thanks a lot. Keep up the good work.

mcdoubleyou commented 12 months ago

Hello,

don't know why, but this won't work for me. The ports are still 3000 and 3001.

Here is my config, hope someone could help.

version: '3.3'
services:
    speedtest:
        restart: unless-stopped
        container_name: openspeedtest2
        networks:
            macvlan:
                ipv4_address: 192.168.1.45
        ports:
            - '80:80'
            - '443:443'
        image: openspeedtest/latest:latest
        volumes:
            - openspeedtest_data:/var/log/letsencrypt
        environment:
            - CHANGE_CONTAINER_PORTS=true
            - HTTP_PORT=80
            - HTTPS_PORT=443
networks:
    macvlan:
        external: true
volumes:
    openspeedtest_data:
        external: true

Thank you!

MekayelAnik commented 12 months ago

Hello,

don't know why, but this won't work for me. The ports are still 3000 and 3001.

Here is my config, hope someone could help.

version: '3.3'
services:
    speedtest:
        restart: unless-stopped
        container_name: openspeedtest2
        networks:
            macvlan:
                ipv4_address: 192.168.1.45
        ports:
            - '80:80'
            - '443:443'
        image: openspeedtest/latest:latest
        volumes:
            - openspeedtest_data:/var/log/letsencrypt
        environment:
            - CHANGE_CONTAINER_PORTS=true
            - HTTP_PORT=80
            - HTTPS_PORT=443
networks:
    macvlan:
        external: true
volumes:
    openspeedtest_data:
        external: true

Thank you! @mcdoubleyou

If you look at the Line 16 of the docker Entrypoint in the below link: https://raw.githubusercontent.com/openspeedtest/Docker-Image/main/files/entrypoint.sh

You can see that You have to set the CHANGE_CONTAINER_PORTS=True You have set it as "true". This has to be specifically "True" and NOT "true" or "TRUE" or "trUe" or "yes" etc. I think you get the point.

@openspeedtest please fix this simple typo issue which is very likely to occur. Thanks in advance. Regards.

wangweitung commented 1 month ago

Hello, don't know why, but this won't work for me. The ports are still 3000 and 3001. Here is my config, hope someone could help.

version: '3.3'
services:
    speedtest:
        restart: unless-stopped
        container_name: openspeedtest2
        networks:
            macvlan:
                ipv4_address: 192.168.1.45
        ports:
            - '80:80'
            - '443:443'
        image: openspeedtest/latest:latest
        volumes:
            - openspeedtest_data:/var/log/letsencrypt
        environment:
            - CHANGE_CONTAINER_PORTS=true
            - HTTP_PORT=80
            - HTTPS_PORT=443
networks:
    macvlan:
        external: true
volumes:
    openspeedtest_data:
        external: true

Thank you! @mcdoubleyou

If you look at the Line 16 of the docker Entrypoint in the below link: https://raw.githubusercontent.com/openspeedtest/Docker-Image/main/files/entrypoint.sh

You can see that You have to set the CHANGE_CONTAINER_PORTS=True You have set it as "true". This has to be specifically "True" and NOT "true" or "TRUE" or "trUe" or "yes" etc. I think you get the point.

@openspeedtest please fix this simple typo issue which is very likely to occur. Thanks in advance. Regards.

this feature is great!