Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwaggerUI is not working in Docker, but works locally. Only the SwaggerUI throws a 404 Not Found #527

Closed
kerkmann opened this issue Mar 17, 2023 · 8 comments · Fixed by #534

Comments

@kerkmann
Copy link
Contributor

Okay, I know this sounds weird ... but: The SwaggerUI is not working inside of Docker. ^^"

Let me explain what I did. When I write down everything like in the example for axum and I start the application with cargo run, I can see the swagger-ui and also see the /docs/openapi.json file.
Now the interesting part, when I compile the code inside docker and provide it inside docker only the swagger-ui endpoint (/docs in this example) is returning a 404 Not Found. But the interesting thing is, all other endpoints are working... Including the /docs/opanapi.json endpoint.
So, only the swagger-ui isn't working inside Docker. ^^"

I thought "maybe it's a compiled problem", so I copied the locally build binary (which worked on the machine and showed the swagger-ui) into the docker container, started it and "boom", no swagger-ui. ^^"
It's so weird that every endpoint is working, also the openapi.json endpoint (which shows the full generated openapi json), but only the swagger-ui HTML-Page is not working. There is really no difference inside the Docker container and my local machine (like I said, I copied the binary to prove my assumption).
I also tried bigger OS containers like ubuntu and smaller ones like alpine, in all containers every endpoint is working, except the swagger-ui. :(

Does someone have an idea what I could test/think of? I'm getting out of ideas. ^^"

@omarmhaimdat
Copy link

I am experiencing the same issue

@juhaku
Copy link
Owner

juhaku commented Mar 17, 2023

That is weird indeed 😮 But based only on this message it is really hard to tell what is going wrong and where. 🤔

I tried to build the todo-axum in in the examples folder as:

  1. I build the app with command
cargo build --release --target=x86_64-unknown-linux-musl
  1. I added a dockerfile like this:
FROM alpine:3.17

RUN mkdir /opt/app

COPY target/x86_64-unknown-linux-musl/release/todo-axum /opt/app

EXPOSE 8080

CMD [ "/opt/app/todo-axum" ]
  1. Run docker build command docker build -t todo-axum:test .
  2. Run the container docker run -p 8080:8080 todo-axum:test
  3. Went to localhost:8080/swagger-ui/ with my browser and Swagger UI showed up.

If you build in debug mode then utoipa-swagger-ui needs the debug-embed flag to be enabled. That is, RustEmbed itself does not embed stuff to the binary in debug builds by default. See more here https://github.com/pyrossh/rust-embed#features.

Also not that you have correct target. that linux-musl is generic linux target meant to be used within docker containers.

Hope these helps.

@kerkmann
Copy link
Contributor Author

Okay, that explains a lot .... you are totally right, it's working with a release build. :)

I created the build in debug mode, and it seems like that the debug-embed flag is not enabled inside Docker. ^^"

Maybe it makes sense that we pinpoint that "issue" out in the Readme, thank you very much! <3

@kerkmann
Copy link
Contributor Author

I've created a small documentation change to pinpoint it better in the README. Maybe it will help out. :3

@juhaku
Copy link
Owner

juhaku commented Mar 17, 2023

Maybe it makes sense that we pinpoint that "issue" out in the Readme, thank you very much! <3

Yeah, actually there is slight hint towards this in utoipa-swagger-ui README.md but it is not obivous to the eye.

@kerkmann
Copy link
Contributor Author

Yeah, actually there is slight hint towards this in utoipa-swagger-ui README.md but it is not obivous to the eye.

Ah yeah, now I see what you mean. It wasn't quite obvious to me and two other people. So spending hours investigating that issue could be solved by pinpointing it out. :)

@juhaku
Copy link
Owner

juhaku commented Mar 18, 2023

Ah yeah, now I see what you mean. It wasn't quite obvious to me and two other people. So spending hours investigating that issue could be solved by pinpointing it out. :)

True 🙂

@juhaku
Copy link
Owner

juhaku commented Mar 21, 2023

Relates to #268

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants