D
D
demnagel2019-07-03 17:55:28
Django
demnagel, 2019-07-03 17:55:28

How to migrate in a dockerfile if the base is in a different container?

Hello friends!, Such a situation:
There is a container with a database and a container for a django application that links to the database and starts itself:

FROM deb_base
COPY vfnd vfnd
CMD ["python", "./vfnd/manage.py", "runserver", "0.0.0.0:8001"]

The downside is that I have to run python vfnd/manage.py migrate manually every time I bring containers up.
I tried to add over CMD RUN ["python", "./vfnd/manage.py", "migrate"] to the dockerfile, but when I try to build the image, it fails with an error on this command (there is no connection).
How can I implement this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Derepko, 2019-07-03
@demnagel

Make the dependency of this container on the database.
https://docs.docker.com/compose/compose-file/#depe...
As a result, you will first start the container with the database, then the container with your code, in which you do python /vfnd/manage migrateeverything and everything works fine

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question