Was able to get it to work with ENTRYPOINT, on my first try. Problem is after I kill the process and do docker-compose up the second time.
I get an error saying database is already up:
api_1 | [debug] QUERY OK source="schema_migrations" db=2.4ms
api_1 | SELECT s0."version"::bigint FROM "schema_migrations" AS s0 FOR UPDATE []
api_1 | [info] Already up
maisie_api_1 exited with code 0
I’m guessing this has something to do with the container trying to do mix ecto.create when the database already exists. How do I configure it such that these ENTRYPOINT commands execute once?
maisie_api_1 exited with code 0 is the error. If this is not an error, I don’t understand how to get this to work. Have you worked with phoenix, postgres and docker before? If so, do you have a sample repository of how this is done, where the app does not exit every time mix ecto.create is run?
My repo is https://github.com/sc4224/maisie-sample/tree/master/maisie_api i need somebody to point out what is wrong in this dockerfile and a step by step example of how to fix this. I can’t find documentation anywhere on how to get mix ecto.create and mix ecto.migrate to run once
You need to run those on startup, not as part of the docker build process. Docker compose builds everything independently first, and THEN it starts things. This is to say, the database isn’t available while building the image.
However I can’t provide more specific advice because I can’t actually get things to compile. I downloaded your project and ran docker-compose build but I get:
Generated elixir_make app
==> argon2_elixir
could not compile dependency :argon2_elixir, "mix compile" failed. You can recompile this dependency with "mix deps.compile argon2_elixir", update it with "mix deps.update argon2_elixir" or clean it with "mix deps.clean argon2_elixir"
** (Mix) "make" not found in the path. If you have set the MAKE environment variable,
please make sure it is correct.
==> maisie_api
ERROR: Service 'api' failed to build: The command '/bin/sh -c mix compile' returned a non-zero code: 1
Either way though, when using docker compose you generally want some kind of startup.sh script that is the command, and it includes on boot stuff.
Funny, I’m back at my PC, and I have to admit, I was able to build the image, also subsequent docker-compose up are working fine (at least if postgres starts before the ecto commands are run).
Additional info: You should not volumes: ["./maisie_app:/app"] in the YAML, that totally defeats the purpose of building in docker first.