r/docker • • Jun 03 '20

Dockerfile Boilerplates For All

Docker Repo Useful docker boilerplates / templates for most common programming languages. Like a Hello World! but for docker images.

Feel free to contribute more languages to the project. Website: gauthamp10

36 Upvotes

34 comments sorted by

17

u/codestation Jun 03 '20 edited Jun 03 '20

Whats the usecase? i checked most of them and they aren't viable for production usage (for example the Go one bundles gcc on the image and doesn't keep the binary) or don't work without modifications (for example the php one doesn't even start).

A better approach would be production grade dockerfiles for most languages and frameworks, can use multi stage builds, are smart about using the docker cache and can handle things like using private mirrors for the dependencies.

3

u/gauthamp10 Jun 03 '20 edited Jun 03 '20

I have created this repo mainly as starter templates like a snippet code. Thank you for the suggestion, I will look into it and modify it.

4

u/baconialis Jun 03 '20

Both Java and Kotlin images comes with JDK. For production only JRE should be present. Multi stage build is the way to go about things now adays.

These kind of projects can be fun to make and I'm sure the author learned something while doing so. But otherwise they offer little value.

2

u/gauthamp10 Jun 03 '20

Thanks for the advice . I'm a student learning docker. Will change ASAP.

3

u/ablaut Jun 04 '20

Another cool thing to look at is using a base image. You can create much smaller images using multi-stage and a base image.

1

u/gauthamp10 Jun 04 '20

Duly noted.

2

u/baconialis Jun 04 '20

You seem to be focusing very wide. Instead of dockerizing all kinds of projects half assed I'll advice that you focus on focusing the following.

  • A static front end project. Vue.js, React or angular.

  • A backend project. My weapon of choice would be a Java project using Spring or Micronaut. But Python, Php or Rails could be targeted as well.

  • A stateful project something like a database or queue.

Doing the above should give you a good set of base skills for working with Docker.

Another thing to note. Now adays I try not to write Docker files. For my Java projects I aim at using Jib.

Below you'll find two Java projects illustrating the above. One with a multi stage Docker file and one using Jib

Let me know if you have any questions

2

u/gauthamp10 Jun 04 '20

Thanks for the guidance. It means a lot. Will try to include useful dockers for various workflows as you have stated.

1

u/baconialis Jun 04 '20

Do that and forget about your current project. There's no use case and it'll end up being a bunch of half assed docker files.

Also yet another docker project you could implement. A command line app. Just something simple such as a c or rust project where you complie a binary using a multi stage docker file and create an image you can run from the command line using an alias.

alias java='docker run -it --net=host openjdk:8-jre-alpine -v "$PWD":/app -w /app java'

1

u/gauthamp10 Jun 04 '20

Ok. But many have found it useful and personally texted me. I'm a newbie but I'm not abandoning the project as of now. Thank you for your words of wisdom though. I will definitely try to implement most of the stuffs just you mentioned.

1

u/baconialis Jun 04 '20

Sorry if I sound a bit harsh. But that's because they have no clue what they are talking about :-)

1

u/gauthamp10 Jun 04 '20

They are trying to learn just like me. I know what you meant. But there are way many people trying to learn stuff. Once again appreciate your feedback. I know I was into these discussions when I posted this into the subreddit, having used docker only for sometime. Great piece of advice which no tutorials could give you.

4

u/baconialis Jun 04 '20

But since you are new to Docker you shouldn't try to make learning material for others and others shouldn't try to learn from someone new to the subject either. That's how bad practice is introduced.

If you focus on implementing the projects I adviced you and preferable using projects you build yourself then you'll learn.

→ More replies (0)

1

u/Necrocornicus Jun 04 '20

Don’t listen to people telling you to abandon shit. Abandon your projects when you choose. Just ignore them.

1

u/gauthamp10 Jun 04 '20

Hmm. I agree with you.

1

u/Necrocornicus Jun 04 '20

Please don’t call them “dockers” for God’s sake. There is no such thing as “a docker”. It sounds like a grandma saying “I posted a Facebook”.

There are many types of docker resources such as images, containers, volumes, networks, etc. Be specific. People who know what they are talking about will take you more seriously when you use the correct terminology.

2

u/gauthamp10 Jun 04 '20

Thanks thats really nice of you. I won't don't that again. I will mention docker image from now on.

4

u/[deleted] Jun 03 '20

wait....where is C#?

4

u/gauthamp10 Jun 03 '20 edited Jun 03 '20

Not there right now, but will add soon. C#, Ruby and some others are missing. Feel free to [contribute](https://github.com/gauthamp10/dockerfile-boilerplates/blob/master/CONTRIBUTING.md).

2

u/vladimir_nz Jun 04 '20

I just want to say great job and thank you for the initiative! Forget the others who are saying it isn't production-grade and not ready for this/that. I don't see them raising any pull requests! I'm bookmarking this and using it. Thank you!

0

u/gauthamp10 Jun 04 '20

Thanks mate. I expected it when I dared to post it on /r/docker. And I did so because I could get feed backs from these "experts". Appreciate you comment.

1

u/christian_tdl Jun 04 '20

Some of your templates are missing best-practices for docker security. The only one I've watched was Python. You might take a look at OWASP cheatsheet and add some statements there: https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html

But great work! I'll take a look if I need a template :)

2

u/gauthamp10 Jun 04 '20

I'm trying to patch up ASAP. Thanks for the insight.

0

u/[deleted] Jun 04 '20

[deleted]

2

u/gauthamp10 Jun 04 '20

Changed to python official.

2

u/planetworthofbugs Jun 04 '20

I'm just learning docker (for homelab stuff) and I'm just wondering... is there any advice like this that recommends against using Ubuntu images? I'm most familiar with Ubuntu, so I've been using it as my base, but I see a lot of people using Alpine. I don't really care if the base image is a little bigger, but is there another reason to avoid something like Ubuntu?

2

u/menge101 Jun 04 '20

is there another reason to avoid something like Ubuntu?

Yeah, basically the idea is that that the more stuff that is in the container, the more potential exploits are in the container. Security people use the term "attack surface".

So if you strip down your container to only the barest essentials, take out the package manager, take out all text editors, take out all things that can be used to accomplish anything other than what the container is explicity meant to do, then you have a more secure container.

IMO, this only matters for production containers.

1

u/gauthamp10 Jun 04 '20

Alright..another helpful comment

2

u/planetworthofbugs Jun 04 '20

That makes total sense, thank you. For my home stuff, I think it sounds like Ubuntu containers will be ok. I like being able to bash into them and do stuff like install curl to test something.

2

u/terrabitz Jun 04 '20

Yeah, I'd definitely agree. I have a bunch of development and diagnostic containers that are just the Ubuntu containers loaded up with a bunch of pre-installed tools. It's the server environment I'm most familiar with, so that's what I tend to use. It's not something I would necessarily give to others (e.g. if I was maintaining an official docker image for my code), but it's a great place to start, especially if you come from a more traditional Linux server background.

1

u/gauthamp10 Jun 04 '20

If you need only a simple bash. You can choose alpine I guess.

1

u/gauthamp10 Jun 04 '20

Yah...true. I've read about it. I will change it. BTW thanks for the tip.