Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cannot propagate alembic revision from container to file tree with docker watch#1370

Unanswered
PierrickLP asked this question inQuestions
Discussion options

First Check

  • I added a very descriptive title here.
  • I used the GitHub search to find a similar question and didn't find it.
  • I searched in the documentation/README.
  • I already searched in Google "How to do X" and didn't find any information.
  • I already read and followed all the tutorial in the docs/README and didn't find an answer.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

N/A

Description

With the new recommendeddocker compose watch command to start the project, any db revision files generated by alembic inside the container will not be replicated in the host system.

Operating System

Linux, Windows

Operating System Details

wsl2 on w11

Python Version

3.12.6

Additional Context

No response

You must be logged in to vote

Replies: 3 comments 8 replies

Comment options

I am facing the same issue. As suggested byDocker documentation, sync only works one way: from host to container. With the current watch setup and not mounting the directory as a volume, generated alembic revision files are not synced back to the host.

I tried adding back the volume mapping but it resulted in the following error:
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "fastapi": executable file not found in $PATH: unknown

You must be logged in to vote
5 replies
@yohaoquan
Comment options

I have found a working workaround (should have thought of it when I made the original comment):

Warning: This kinda breaksdocker compose watch in that it keeps re-adding those files back to the container, which then gets synced back to the host because of volume mapping, then triggerswatch's sync again... Only do this when you are creating a revision and revert the change once you are done.

Change the backend volume to include the alembic folder:

    volumes:      - ./backend/htmlcov:/app/htmlcov      - ./backend/app/alembic:/app/app/alembic

You could drill down more to only the versions folder.

@josephna76
Comment options

I'm having this same issue. When I added those backend volumes, my docker didn't build so I still wasn't able to get it to work - see error message below. Can we make this into an issue?

Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "fastapi": executable file not found in $PATH: unknown (app)

@yohaoquan
Comment options

@josephna76 It's been a while since I did that but I believe adding only the alembic folder (and not the whole backend folder) is how I solved it when I encountered that issue.

The drawback of this is that live reload of fastapi will not work. I am developing it locally in the meantime but yes, I would want this to be an issue as well. Looks like the maintainers are not actively looking at discussions anyway.

@meme8383
Comment options

Try excluding the alembic folder from watch to fix the refresh

@josephna76
Comment options

Great, thanks yohaoquan and meme8383! I tried your solutions and it seemed to work, but I went with the documented solution of using SQLModel directly without Alembic while this gets resolved.

Comment options

As@yohaoquan mentioned correctlydocker compose watch ordocker compose -v only works one way. So all actions taken in the docker containers are not transferred back to the host system. This was recently introduced in thiscommit.

I would suggest to update the documentation where the alembic revisions are still advised to be run in the container. Actually actions should be done from now on the host. As well adding packages should be done on the host (This actually is adjusted in the docs, thx@tiangolo :)).

Again run the following actions on yourHOST not in the docker container.

  1. To run the alembic revisions in the host container make sure your docker containers are running (Especially the db is needed so you can also just rundocker compose up db.

  2. Make sure you are in your virtual environment fromuv. Runsource .venv/bin/activate in the/backend folder to activate it.

  3. go to the/backend folder and runalembic revision --autogenerate -m "Add column last_name to User model"

  4. And run the migration.alembic upgrade head

I was in the lucky position to delete all my databases and start from scratch so I had no issues after doing it accidentally in the docker container.

You must be logged in to vote
3 replies
@Sam1320
Comment options

I created this small script to expose the vars in .env so that the settings instance can work even when running locally.

# db_revision.shexport PYTHONPATH=$(pwd)# turn on auto-exportset -a# expose env vars in .envsource ../.env# turn off auto-exportset +a# revisionalembic revision --autogenerate -m "$1"

then u can do./script/db_revision "add column"

@adham404
Comment options

I did the steps you mentioned but I am getting this error
sqlalchemy.exc.OperationalError: (psycopg.OperationalError) connection failed: connection to server at "127.0.0.1", port 5432 failed: FATAL: password authentication failed for user "postgres" (Background on this error at: https://sqlalche.me/e/20/e3q8)

have you by any chance faced the same issue? I am sure of the credentials I checked them several times. Also the credentials work properly in the adminer login.

@stevleibelt
Comment options

@adham404

best guess, you've missed to start the shell in the docker container?
docker compose exec -it backend bash.

Your script tries to connect to a database on your local machine on port 5432, but as far as I get thedocker-compose.yml, the port 5432 is never exposed outside the docker stack.

Comment options

For anyone still having issues. Firstly, the issue seems to arise mostly among SELinux distros. Secondly,@yohaoquan above is nearly there with his solution, however there is the"z"flag missing as shown below:

volumes:      - ./migrations:/app/migrations:z      - ./migrations/versions:/app/migrations/versions:z

I wrote a comprehensive solutionhere that allows you to have your alembic files in your container showing in your local files whilst not breaking your compose watch feature as in the solution by@yohaoquan

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Labels
questionFurther information is requested
9 participants
@PierrickLP@stevleibelt@yohaoquan@meme8383@willhama@Sam1320@adham404@josephna76@Suaralanre

[8]ページ先頭

©2009-2025 Movatter.jp