Dockerfiles – best practices

Now that we have covered Dockerfile instructions, let's take a look at the best practices of writing our own Dockerfiles:

  • You should try to get into the habit of using a .dockerignore file. We will cover the .dockerignore file in the next section; it will seem very familiar if you are used to using a .gitignore file. It will essentially ignore the items you have specified in the file during the build process.

  • Remember to only have one Dockerfile per folder to help you organize your containers.

  • Use version control for your Dockerfile; just like any other text-based document, version control will help you move forward, but only backward as necessary.

  • Minimize the number of packages you need per image. One of the biggest goals you want to achieve while building your images is to keep them as small as possible. Not installing unnecessary packages will greatly help in achieving this goal.

  • Execute only one application process per container. Every time you need a new application, it is best practice to use a new container to run that application in. While you can couple commands into a single container, it's best to separate them. Keep things simple; over complicating your Dockerfile will add bloat and also potentially cause you issues further down the line.

  • Learn by example, Docker themselves have quite a detailed style guide for publishing the official images they host on Docker Hub, documented at https://github.com/docker-library/official-images/.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset