Closed lukasitaly closed 2 months ago
I'm not sure I understand what you try to achieve.
You say port 8080 is already in use, but you also use compose.yaml, which implies a Docker container.
If you don't use Docker, and simply run the binary, you can use this:
WT_BIND="[::]:8070" ./workout-tracker
The output should contain a line similar to this (note the [::]:8070
):
2:52PM INF Starting web server on [::]:8070 app=workout-tracker version=local sha=local module=app
If you use a compose file and Docker, you can simply use a different port in the host port
part:
version: "3.8"
services:
workout-tracker:
image: ghcr.io/jovandeginste/workout-tracker:master
restart: unless-stopped
ports:
# Host Port:Container Port
- 8070:8080 # This is where we define the port mapping
volumes:
- ./data:/data
environment:
- WT_JWT_ENCRYPTION_KEY=my-secret-key
If you prefer to use the same port inside and outside of the container, you can use this:
version: "3.8"
services:
workout-tracker:
image: ghcr.io/jovandeginste/workout-tracker:master
restart: unless-stopped
ports:
# Host Port:Container Port
- 8070:8070 # This is where we define the port mapping
volumes:
- ./data:/data
environment:
- WT_JWT_ENCRYPTION_KEY=my-secret-key
- WT_BIND="[::]:8070"
I'm sorry if I wasn't very clear, I'm trying my best but am still at the beginning of my Docker journey so I'm not always sure what I'm doing.
Anyways, that's what I did. I tried again, deleted everything and copied your code (the last sample with the same port inside and outside of the container) into the compose.yaml file, just changed the secret key. I still get the same error:
panic: listen tcp: address "[::]:8070": too many colons in address
This repeats time and time again in the logs:
workout-tracker-1 | {"time":"2024-07-10T13:17:39.105649464Z","level":"INFO","msg":"Connecting to the database 'sqlite': ./database.db","app":"workout-tracker","version":"master","sha":"4101e4a72e303f2fea1175317f7e7f70d9d0d6ff","module":"app"}
workout-tracker-1 | {"time":"2024-07-10T13:17:39.125805448Z","level":"INFO","msg":"Starting web server on \"[::]:8070\"","app":"workout-tracker","version":"master","sha":"4101e4a72e303f2fea1175317f7e7f70d9d0d6ff","module":"app"}
workout-tracker-1 | {"time":"2024-07-10T13:17:39.125954379Z","level":"INFO","msg":"Worker started...","app":"workout-tracker","version":"master","sha":"4101e4a72e303f2fea1175317f7e7f70d9d0d6ff","module":"app","module":"worker"}
workout-tracker-1 | panic: listen tcp: address "[::]:8070": too many colons in address
workout-tracker-1 |
workout-tracker-1 | goroutine 1 [running]:
workout-tracker-1 | main.main()
workout-tracker-1 | /app/main.go:35 +0x1ec
You say port 8080 is already in use, but you also use compose.yaml, which implies a Docker container Since I'm a beginner, I'm not entirely sure what you're trying to say here, could you please explain in further detail?
Thanks again
If you look at the logs, you see this: "Starting web server on \"[::]:8070\""
(quotes, with escaped quotes (\"
) inside)
While in mine, it was: INF Starting web server on [::]:8070
(no quotes)
I suspect the quotes are kept, while they shouldnt. Can you remove the quotes around the value in the compose.yaml file?
- WT_BIND=[::]:8070
What I mean with
You say port 8080 is already in use, but you also use compose.yaml, which implies a Docker container
Your container has its own port space, which means you can use any port inside the container (unless you use the host network namespace, which you shouldn't for this type of application).
This means you can keep the application on port 8080 inside the container (you don't need to change its configuration), and use the Docker port mapping system, to use a different port outside the container (ie. on the host). This means that eg. port 8070 on the host, will map to port 8080 inside the container.
You achieve this by simply using this snippet in the compose file:
ports:
# Host Port:Container Port
- 8070:8080 # This is where we define the port mapping
You remove anything with bind or WT_BIND, don't change the port of the application inside the container.
When the container starts, you can surf to localhost:8070, and still reach the application which listens on port 8080; like magic (unless you understand how it works, then it's just technology, see the 3rd law)
Oh well that was an easy solution, the problem were indeed the quotes. Thank you so much! :)
Your container has its own port space
So that means for every container I create, I have all ports available? If I create a container with port 8080, then I can create another one with port 8080 since it's isolated right?
Oh well that was an easy solution, the problem were indeed the quotes. Thank you so much! :)
Your container has its own port space
So that means for every container I create, I have all ports available? If I create a container with port 8080, then I can create another one with port 8080 since it's isolated right?
Exactly, that's the default behavior. You can override this (eg. use the "host network", which will map all container ports to the host's network interface).
More information here: https://docs.docker.com/network/
Perfect, thanks for the clarification!
Port 8080 is not free, so I had to use 8070. But I'm having issues. I've tried everything I know and tried researching, but the issue doesn't seem to go away. When following the guide, I get a blank page "Unable to connect".
I tried:
Without workout-tracker.yaml
With workout-tracker.yaml
With "WT_BIND" in compose.yaml
With "bind" in workout-tracker.yaml
With "jwt_encryption_key" in workout-tracker.yaml
Using "0.0.0.0:8070" instead of "[::]:8070" in both "WT_BIND" and "bind"
Port 8070 is free
Firewall doesn't block
When I use "WT_BIND" and/or "bind" I finally get an error:
panic: listen tcp: address "[::]:8070": too many colons in address
How can I proceed? Thanks in advance