DevOps & Config Tools

Dockerfile Generator

Choose your stack, enter the version, port and start command, and get a Dockerfile that follows current good practice: small base images, dependency layers that cache well, multi-stage builds where they help, a non-root user and a health check. A matching .dockerignore and the build commands come with it.

  • Runs in your browser
  • No sign-up
  • Free to use

The major version your project is tested with, for example 22 for Node.js or 3.13 for Python.

Written as you would type it in a terminal.

Leave empty if index.php is in the project root.

Options

Build and run


        

    How to use Dockerfile Generator

    1. Select what you are packaging and the runtime version.
    2. Enter the build and start commands and the port the app listens on.
    3. Choose whether to run as a non-root user and add a health check.
    4. Save the Dockerfile and .dockerignore in your project root, then build with the commands shown.

    Dockerfile Generator features

    Five stacks

    Node.js servers, front-end builds served by Nginx, Python web apps, PHP with Apache, and Go binaries.

    Multi-stage builds

    Build tools and development dependencies stay in the build stage; the final image holds only what runs.

    Cache-friendly order

    Dependency manifests are copied and installed before the source, so code changes do not reinstall everything.

    Safer defaults

    Non-root user, production environment settings and exec-form commands that receive stop signals.

    Health check

    A HEALTHCHECK suited to the tools present in each base image.

    .dockerignore included

    Keeps .git, dependencies, secrets and build output out of the build context.

    When to use Dockerfile Generator

    • Containerising an existing application for the first time.
    • Replacing a single-stage Dockerfile that produces a very large image.
    • Getting a correct Dockerfile for a stack you do not use every day.
    • Preparing an app for a platform that deploys from a Dockerfile.

    Dockerfile Generator FAQ

    Why copy package.json before the rest of the code?

    Docker builds an image in layers and reuses a layer when its inputs have not changed. If the manifest and lock file are copied and installed first, that expensive step is reused for every build in which only source code changed. Copying everything at once would reinstall all dependencies after each edit.

    What is a multi-stage build?

    A Dockerfile with several FROM lines. Earlier stages contain compilers, bundlers and development dependencies. The last stage starts from a clean base and copies only the results. The final image is smaller, starts faster and contains less software that could have vulnerabilities.

    Why should the container not run as root?

    A process running as root inside a container has more ways to affect the host if it is compromised. Running as an unprivileged user costs nothing and is required by many platforms. The exception is software such as Apache that starts as root to open a low port and then drops privileges for the worker processes.

    Why does my app not respond on the published port?

    Most often because it listens on 127.0.0.1 inside the container, which is not reachable from outside. Configure it to listen on 0.0.0.0. Also check that the port in EXPOSE and in “docker run -p” is the one the app really uses.

    Where do secrets go?

    Not in the Dockerfile and not in the image. Anything written with ENV or copied in is readable by everyone who can pull the image. Pass secrets at run time as environment variables or through your platform's secret store; the .dockerignore keeps .env files out of the build.

    Is the result ready for production?

    It is a solid starting point. Review the base image tag, add system packages your app needs, and build it in your pipeline with an image scanner. Pinning the base image to an exact version or digest makes builds fully reproducible.

    What makes a good Dockerfile

    A Dockerfile is a recipe: start from a base image, add files, run commands, and declare how the container starts. Any recipe that produces a working container is valid, yet the differences between a careless and a careful one are large. The same application can end up as a 1.2 GB image that rebuilds from scratch on every change, or as an 80 MB image that rebuilds in seconds.

    Three ideas account for most of that difference. The first is the choice of base image. Slim and Alpine variants leave out compilers and tools that a running application does not need. The second is layer order. Instructions are cached from the top down, and the cache breaks at the first instruction whose input changed, so things that change rarely, such as dependencies, belong above things that change often, such as source code. The third is separating build from run with stages, so that the toolchain never reaches the final image.

    How the process starts matters as well. In exec form, written as a JSON array, the application is the main process of the container and receives the stop signal directly, which lets it finish requests and close connections. In shell form, a shell sits in between and usually does not pass the signal on, and the container is killed after a timeout. A health check gives the platform a way to tell a running process from a working one, so that it can restart or stop routing traffic to a container that hangs.

    The .dockerignore file is part of the picture. Everything in the project folder is sent to the builder unless excluded. Leaving out the .git folder and local dependencies speeds up every build, and leaving out .env files prevents the most common way secrets end up in images. Treat images as public: assume anyone who obtains one can read every file and every layer in it.

    Other useful tools