Hello, I’m new to Docker and have been running into an issue.
When I run docker-compose, I have both my api and db containers running. However, when I navigate to the port, it seems that the port is not running. Any help would be greatly appreciated.
what exactly is the error-message and what was entered as URL into your browser?
Did you try to get logging data - either bei using
docker container <container-name> logs (which is
docker container api-1 logs in your case) on the command line or by clicking on the containername in the gui? Sometimes you can see helpful messages there, e.g. “could not connect to database”, “not allowed to write file”, …
Did you ensure that the application within the
api-1-container is listening on port 8080? It happened to me in the past, that I forwarded computer’s port 80 to container’s port 80 but the application within the container was listening on port 3000
Have you checked that the application is running fine outside of the container? Maybe you have to change some application-settings (database-URL, …) to do so.
Update: I have tried to hard code my env variables in my application and I am no longer getting any error messages or logs; however, the port is still not working.
Sorry for the delay.
The application is listening on which IP-address? If you configured the application to listen on
127.0.0.1 it will not work within the container as the container’s localhost is not the same as the computer’s localhost. The applicatin has to listen on ip-address
At this point I would try the following:
- try to start the app-container manually (without
docker compose) with an interactive shell instead of the application
docker run -it <imagename> bash and from this container’s shell start the application and check for errormessages
- try to add some more debug-output to the console (e.g., the ip and port the app is listening on, the connection-string used for database-connection, queries sent to database, …) to see where the application is doing what.
No Worries, I was able to figure it out! Super silly mistake on my part. Changing the address to 0.0.0.0 fixed it for me.