mathias21 / KtorEasy

Suggested Ktor architecture
GNU General Public License v3.0
260 stars 30 forks source link

Dockerfile build fails adding new user when using openjdk:11-jre-slim #5

Closed polaroidkidd closed 3 years ago

polaroidkidd commented 3 years ago

First, thanks for the great reference to get into KTOR.

I have been stumbeling across these lines in the Dockerfile

# Creating user
ENV APPLICATION_USER 1033
RUN adduser -D -g '' $APPLICATION_USER

Is there any specific reason you choose to run the application with a different user (other than not running containers as root)?

mathias21 commented 3 years ago

Hi @polaroidkidd

The user number "1033" has to be the ID of an already existing user in "your system" (Docker host machine), with access to the folders where you are going to run container's volumes. For security reasons, and also to delimit what a container can do, it is better to not execute your commands with root user. So the only other reason (out of security) is to be sure that user that runs commands in container can make use of volume's folder (with the correct rights there). Related with openjdk:11-jre-slim problem, I think you don't have that user ID in your system so this is why this is failing. You need to define a new user (or use an existing one), create host machine volume folders with that user and then change "1033" by your user's ID. I hope this helps. Please let me know if you have other questions.

polaroidkidd commented 3 years ago

sorry for the long break, I'm using this to get to terms with ktor and kotlin simultaneously in my off time.

Anyway,

The user number "1033" has to be the ID of an already existing user in "your system"

Is the user id 1033 in any way significant? I'm running (my own version of this) on linux as the root user (since it's just a side-project, I'm not worried about security), but I supposed I could try and run this as "me". Do you think it'd be possible to make the start up scripts use a combination of whoami and id -u to get the current user ID? That way anyone checking this architecture out doesn't have to create a use just to get it up and running.

On another note, I've noticed a utter and complete lack of useful guides/tutorials in the realm of ktor. Have you thought about making a series about this? It seems to have a good approach and includes all the crud basics.

mathias21 commented 3 years ago

Hi @polaroidkidd

Is the user id 1033 in any way significant?

That id 1033 is just the user id, you can use the one you prefer, as long as it has permissions in the folders you will use for reading/writing in the host machine from Docker.

Do you think it'd be possible to make the start up scripts use a combination of whoami and id -u to get the current user ID?

It may be possible, I'm open for suggestions/improvements, so if you give it a chance, make a PR and I will be happy to add this to the codebase.

On another note, I've noticed a utter and complete lack of useful guides/tutorials in the realm of ktor

This is my Medium account, I have some articles there explaining this repository: https://medium.com/@math21 This is a nice video from Ryan Harter from Kotlinconf 2018 explaining Ktor: https://www.youtube.com/watch?v=V4PS3IjIzlw You also have documentation here: https://ktor.io/docs/creating-http-apis.html And a live chat in Slack: https://kotlinlang.slack.com/messages/ktor/ All people in that chat is really helpful, so you can get your questions solved.

sorry for the long break, I'm using this to get to terms with ktor and kotlin simultaneously in my off time.

No worries, this was also my "hobby". I'm an Android developer, not Backend :D

polaroidkidd commented 3 years ago

thanks for the great resources. I just tried it again and it appears the issue was entirely on my end.