Docker container not port forwarding
Hello, yesterday I was in here as well regarding some problems with my port forwarding.
Im trying to get my docker container to run on localhost:8080 and also make use of some certificates because I want to use another local project to test out the endpoints on my api which I am trying to deploy.
I have the following code
Dockerfile:
Docker-compose:
Appsettings:
Launchsettings:
55 Replies
When i run
docker compose up --build
i get the following resultThough when I am trying to connect to localhost:8080 it doesnt give me a response from the website nor do i get any response inside the logs
It also doesnt seem to not properly copy over the certs like ive requested in my dockerfile
Did you get output indicating the docker image was actually being rebuilt?
Id assume so?
Im quite new when it comes to certificates but I supposedly need them to have my local react application talk to my local api
Just for interest, try
docker-compose build --no-cache --progress=plain
. See the actual output from the build processhttps://paste.ofcode.org/c4iE6KTadDP8btcADV9C5V
This is the output
Oh. You put your certs in your base image?
Same with
EXPOSE
, DOTNET_URLS
, etcHonestly Im just following what people on the internet are doing
Ah, no. You do
FROM base AS final
Im not instantly seeing anything thats problematic
What makes you think it isn't copying over the keys?
as the 2 screenshots I send above
It seems like it did create a mount folder called Certs
But it is empty
I'm not sure what those screenshots are from, and the second one does show the certs?
/certs:/Certs
-- your certs are in /app/certs
no?Inside the app folder is my certs folder which holds the certificate
So what is the
/certs:/Certs
line trying to do?It should change the ownership of the directory and its ocntents to the user "app" and the group "app"
afaik
This is yet again just something I see everyone doing online
Do you know what the line
/certs:/Certs
does?
It creates a bind mount from /certs
in the container, to /Certs
on your local filesystem. But /certs
in the container doesn't contain your certificates -- you put them in /app/certs
. So it's no surprise that /certs
and /Certs
are empty!
I'm also not sure what you're trying to do with that bind mount. You've put the certs inside the docker image already. Why are you then trying to bind that folder back to your local filesytem?🥲
So I dont even need that piece of code? As that cert file is already being copied because its inside my project?
I just need to reference everything to that folder?
It's really hard to help someone whose question is "I'm not going to tell you what I'm trying to do, but I've copied this random bit of code from the internet, and it doesn't do what I expect. But I'm not going to tell you what I want it to do"
What are you trying to do?
Im sorry, ill rephrase my question.
Do you want your certs to be in
/certs
or /app/certs
?
Do you want them to even be in the docker image, or do you want them to be on your local filesystem, and you bind mount them into your container?So as I mentioned before I am trying to talk from my local ReactJs project to my API which I want to run in docker. Initially I just had it run like anything else and it worked just fine. But after calling one of my endpoints using "localhost:8080" I've gotten shown a log in which I was required to add a certificate to trust "dotnet dev-certs https --trust" though it did create the pfx file it didnt seem to be present in my docker container which remained giving me that same problem. So I guess I want my API to accept that certificate inside my docker container so these problems can be resolved.
Could you answer my two questions above please?
in
/cerst
I supposeYou have a mix of
"Path": "./certs/aspnetapp.pfx",
and "path": "Certs/aspnetapp.pfx",
currentlyIm not quite sure which one is beneficial, but I reckon just in my docker image
It depends on whether you want them to be present in the image itself -- so anyone who gets a copy of the image also gets a copy of the certs -- or whether you want to keep them a bit more private and only provide them when you actually run the container
The latter I'd prefer
OK, so:
1. Remove the code to copy the key into the docker image (the
COPY "Certs/aspnetapp.pfx" "/app/certs/aspnetapp.pfx"
etc)
2. If you want them in /certs
, keep the bind mount the same, but change your "Path": "./certs/aspnetapp.pfx"
to /Certs/aspnetapp.pfx
(I think?)
3. Manually copy the certs into the Certs
mount folder after the container is createdauthapi-1 | Unhandled exception. System.IO.FileNotFoundException: Could not find file '/Certs/aspnetapp.pfx'.
Ive removed the copy lineSo yep, copy the certs into the
Certs
folder manuallyOh sorry, it's
/certs
inside the container, not /Certs
You mount /Certs
to /certs
Im a bit lost now,
Did you want me to also remove the other code after that COPY inside my dockerfile or just that line?
"Path": "./certs/aspnetapp.pfx"
needs to be "Path": "/certs/aspnetapp.pfx"
, not "Path": "/Certs/aspnetapp.pfx"
Yup I have that now
And?
authapi-1 | Unhandled exception. System.IO.FileNotFoundException: Could not find file '/certs/aspnetapp.pfx'.
C:\Users\r\source\repos\authapi\Certs\aspnetapp.pfx
Can you look here again?
It doesnt even get that far to show me the files inside the container
authapi-1 | Hosting failed to start
authapi-1 | System.IO.FileNotFoundException: Could not find file '/certs/aspnetapp.pfx'.
authapi-1 | File name: '/certs/aspnetapp.pfx'
docker compose build goes fine
Hmm, that's irritating. Open a shell directly in the container, something like
docker run --rm -it --entrypoint bash authapi:latest
Ah, no, that won't do the bind mount
Change your ENTRYPOINT to /bin/bash
for the moment, start in docker-compose, then docker exec -it authapi-authapi-1 bash
\authapi> docker exec -it authapi-authapi-1 bash
What's next:
Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug authapi-authapi-1
Learn more at https://docs.docker.com/go/debug-cli/
Error response from daemon: container bd6f4730420cd78b766435487f0e4deb4c127e59c624261b4b98370f803546fa is not running
You need to start it with docker-compose
https://paste.ofcode.org/4SXvtJTJAKsAFs7cqHpgD7
thats what I did no?
or am i overlooking something
Well I think ive managed to solve the problem
I redid everything, even generated a new certificate
And now it works