{"id":13509062,"url":"https://github.com/Recruitee/mix_docker","last_synced_at":"2025-03-30T13:31:25.610Z","repository":{"id":57527589,"uuid":"69954074","full_name":"Recruitee/mix_docker","owner":"Recruitee","description":"Put your Elixir app production release inside minimal docker image","archived":true,"fork":false,"pushed_at":"2018-06-07T16:45:03.000Z","size":59,"stargazers_count":334,"open_issues_count":15,"forks_count":52,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-10-28T12:38:28.970Z","etag":null,"topics":["deployment","distillery","docker","elixir","mix"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Recruitee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-04T10:17:28.000Z","updated_at":"2024-10-27T03:25:06.000Z","dependencies_parsed_at":"2022-09-13T03:12:23.132Z","dependency_job_id":null,"html_url":"https://github.com/Recruitee/mix_docker","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Recruitee%2Fmix_docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Recruitee%2Fmix_docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Recruitee%2Fmix_docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Recruitee%2Fmix_docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Recruitee","download_url":"https://codeload.github.com/Recruitee/mix_docker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222552369,"owners_count":17002054,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deployment","distillery","docker","elixir","mix"],"created_at":"2024-08-01T02:01:02.465Z","updated_at":"2024-11-01T09:30:25.995Z","avatar_url":"https://github.com/Recruitee.png","language":"Elixir","funding_links":[],"categories":["Release Management","Elixir"],"sub_categories":[],"readme":"# mix docker\n\n## 🚨🚨 This project is now obsolete and abandoned! 🚨🚨\n\nWith docker multi-stage builds you can simply use:\n```dockerfile\n# Dockerfile\nFROM elixir:1.6.5-alpine as build\n\n# install build dependencies\nRUN apk add --update git\n\n# prepare build dir\nRUN mkdir /app\nWORKDIR /app\n\n# install hex + rebar\nRUN mix local.hex --force \u0026\u0026 \\\n    mix local.rebar --force\n\n# set build ENV\nENV MIX_ENV=prod\n\n# install mix dependencies\nCOPY mix.exs mix.lock ./\nCOPY config ./\nCOPY deps ./\nRUN mix deps.compile\n\n# build release\nCOPY . .\nRUN mix release --no-tar --verbose\n\n# prepare release image\nFROM alpine:3.6\nRUN apk add --update bash openssl\n\nRUN mkdir /app \u0026\u0026 chown -R nobody: /app\nWORKDIR /app\nUSER nobody\n\nCOPY --from=build /app/_build/prod/rel/myapp ./\n\nENV REPLACE_OS_VARS=true\nENV HTTP_PORT=4000 BEAM_PORT=14000 ERL_EPMD_PORT=24000\nEXPOSE $HTTP_PORT $BEAM_PORT $ERL_EPMD_PORT\n\nENTRYPOINT [\"/app/bin/myapp\"]\n```\n\nand standard `docker build`.\n\n\n\n\n## OLD README CONTENT\n\n[![Build Status](https://travis-ci.org/Recruitee/mix_docker.svg?branch=master)](https://travis-ci.org/Recruitee/mix_docker)\n\nPut your Elixir app inside minimal Docker image.\nBased on [alpine linux](https://hub.docker.com/r/bitwalker/alpine-erlang/)\nand [distillery](https://github.com/bitwalker/distillery) releases.\n\n## Installation\n\n  1. Add `mix_docker` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:mix_docker, \"~\u003e 0.5.0\"}]\nend\n```\n\n  2. Configure Docker image name\n\n```elixir\n# config/config.exs\nconfig :mix_docker, image: \"recruitee/hello\"\n```\n\n  3. Run `mix docker.init` to init distillery release configuration\n\n  4. Run `mix docker.build` \u0026 `mix docker.release` to build the image. See [Usage](#Usage) for more.\n\n\n## Guides\n\n- [Getting Started Tutorial](http://teamon.eu/2017/deploying-phoenix-to-production-using-docker/)\n- [Setting up cluster with Rancher](http://teamon.eu/2017/setting-up-elixir-cluster-using-docker-and-rancher/)\n- [Phoenix App Configuration Walkthrough](https://shovik.com/blog/8-deploying-phoenix-apps-with-docker)\n\n## Usage\n\n### Build a release\nRun `mix docker.build` to build a release inside docker container\n\n### Create minimal run container\nRun `mix docker.release` to put the release inside minimal docker image\n\n### Publish to docker registry\nRun `mix docker.publish` to push newly created image to docker registry\n\n### All three in one pass\nRun `mix docker.shipit`\n\n### Customize default Dockerfiles\nRun `mix docker.customize`\n\n\n## FAQ\n\n#### How to configure my app?\n\nUsing ENV variables.\nThe provided Docker images contain `REPLACE_OS_VARS=true`, so you can use `\"${VAR_NAME}\"` syntax in `config/prod.exs`\nlike this:\n\n```elixir\nconfig :hello, Hello.Endpoint,\n  server: true,\n  url: [host: \"${DOMAIN}\"]\n\nconfig :hello, Hello.Mailer,\n  adapter: Bamboo.MailgunAdapter,\n  api_key: \"${MAILGUN_API_KEY}\"\n```\n\n#### How to configure the image tag?\n\nBy default, the image tag uses the following format: `{mix-version}.{git-count}-{git-sha}`\nYou can provide your own tag template in `config/prod.exs` like this:\n\n```elixir\n# config/config.exs\nconfig :mix_docker,\n  tag: \"dev_{mix-version}_{git-sha}\"\n```\n\nAdditionally, you can pass the tag as an argument to `mix docker.publish` and `mix docker.shipit`:\n\n```bash\nmix docker.publish --tag \"{mix-version}-{git-branch}\"\n```\n\nSee below for a list of possible variables\n\n| Variable        | Description                            |\n|-----------------|----------------------------------------|\n| `{mix-version}` | Current project version from `mix.exs` |\n| `{rel-version}` | Default distillery release version     |\n| `{git-sha}`     | Git commit SHA (10 characters)         |\n| `{git-shaN}`    | Git commit SHA (N characters)          |\n| `{git-count}`   | Git commit count                       |\n| `{git-branch}`  | Git branch                             |\n\n\n#### What version of Erlang/Elixir is installed by default?\nThe default dockerfiles are based on [bitwalker/alpine-erlang](https://github.com/bitwalker/alpine-erlang) and elixir installed from [apk repository](https://pkgs.alpinelinux.org/packages?name=elixir\u0026branch=\u0026repo=\u0026arch=\u0026maintainer=)\n\nThe following table summarizes the default versions:\n\n| mix_docker version   | alpine   | erlang   | elixir                             |\n|----------------------|----------|----------|------------------------------------|\n| up to `0.3.2`        | `3.4`    | `18.3`   | `elixir@edge` at the time of build |\n| `0.4.0`              | `3.5`    | `19.2`   | `elixir@edge=1.4.1-r0`             |\n| `0.4.1`              | `3.5`    | `19.2`   | `elixir@edge=1.4.2-r0`             |\n\nPlease note that you can use any version you want by customizing your dockerfiles. See `mix docker.customize` for reference.\n\n\n#### How to attach to running app using remote_console?\n\nThe easiest way is to `docker exec` into running container and run the following command,\nwhere `CID` is the app container IO and `hello` is the name of your app.\n\n```bash\ndocker exec -it CID /opt/app/bin/hello remote_console\n```\n\n#### [Using alternative Dockerfiles](https://github.com/Recruitee/mix_docker/wiki/Alternative-Dockerfiles)\n\n#### How to install additional packages into build/release image?\n\nFirst, run `mix docker.customize` to copy `Dockerfile.build` and `Dockerfile.release` into your project directory.\nNow you can add whatever you like using standard Dockerfile commands.\nFeel free to add some more apk packages or run some custom commands.\nTIP: To keep the build process efficient check whether a given package is required only for\ncompilation (build) or runtime (release) or both.\n\n#### How to move the Dockerfiles?\n\nYou can specify where to find the two Dockerfiles in the config.\n\n```elixir\n# config/config.exs\nconfig :mix_docker,\n  dockerfile_build: \"path/to/Dockerfile.build\",\n  dockerfile_release: \"path/to/Dockerfile.release\"\n```\n\nThe path is relative to the project root, and the files must be located inside\nthe root.\n\n\n#### How to configure an Umbrella app?\n\nThe default build Dockerfile does not handle the installation of umbrella app\ndeps, so you will need to modify it to match the structure of your project.\n\nRun `mix docker.customize` and then edit `Dockerfile.build` to copy across\neach of your umbrella's applications.\n\n```dockerfile\nCOPY mix.exs mix.lock ./\n\nRUN mkdir -p apps/my_first_app/config\nCOPY apps/my_first_app/mix.exs apps/my_first_app/\nCOPY apps/my_first_app/config/* apps/my_first_app/config/\n\nRUN mkdir -p apps/my_second_app/config\nCOPY apps/my_second_app/mix.exs apps/my_second_app/\nCOPY apps/my_second_app/config/* apps/my_second_app/config/\n\n# etc.\n```\n\n\n#### How to configure a Phoenix app?\n\nTo run a Phoenix app you'll need to install additional packages into the build image: run `mix docker.customize`.\n\nModify the `apk --no-cache --update add` command in the `Dockerfile.build` as follows (add `nodejs` and `python`):\n\n```\n# Install Elixir and basic build dependencies\nRUN \\\n    echo \"@edge http://nl.alpinelinux.org/alpine/edge/community\" \u003e\u003e /etc/apk/repositories \u0026\u0026 \\\n    apk update \u0026\u0026 \\\n    apk --no-cache --update add \\\n      git make g++ \\\n      nodejs python \\\n      elixir@edge \u0026\u0026 \\\n    rm -rf /var/cache/apk/*\n```\n\nInstall nodejs dependencies and cache them by adding the following lines before the `COPY` command:\n\n```\n# Cache node deps\nCOPY package.json ./\nRUN npm install\n```\n\nBuild and digest static assets by adding the following lines after the `COPY` command:\n\n```\nRUN ./node_modules/brunch/bin/brunch b -p \u0026\u0026 \\\n    mix phoenix.digest\n```\n\nAdd the following directories to `.dockerignore`:\n\n```\nnode_modules\npriv/static\n```\n\nRemove `config/prod.secret.exs` file and remove a reference to it from `config/prod.exs`. Configure your app's secrets directly in `config/prod.exs` using the environment variables.\n\nMake sure to add `server: true` to your app's Endpoint config.\n\nBuild the images and run the release image normally.\n\nCheck out [this post](https://shovik.com/blog/8-deploying-phoenix-apps-with-docker) for detailed walkthrough of the Phoenix app configuration.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRecruitee%2Fmix_docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRecruitee%2Fmix_docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRecruitee%2Fmix_docker/lists"}