Closed EMCain closed 4 years ago
I can kick this one off. Was also thinking of a quick guide to using VSCode to attach to a container / open within a container for similar functionality.
I can kick this one off. Was also thinking of a quick guide to using VSCode to attach to a container / open within a container for similar functionality.
Good idea - VSCode runs on Linux, Mac and Windows.
Appears #8 was meant to address this issue? Is all behavior needed addressed? @jbeyer16 @znmeb
Looks good to me - I just installed VSCode on my laptop (both Windows and Linux)
I think it handles at least the Windows/Mac manage_py
scripts part. There's also some help provided on accessing inside the Docker container for any other use cases. That's a bit broad, so maybe new issues should be created if specific needs arise. Also I didn't address the:
directly access the DB with PSQL
@znmeb it seems that may be accomplished with how we've used pgAdmin before? Is there any sense in addressing that here or at least opening a new issue if we want to discuss PSQL vs pgAdmin?
@jbeyer16 I'd let the people who are doing the heavy lifting use the tools that work for them rather than have to maintain more tools. :-) Who actually needs to directly access the database as opposed to using it the way Django does - as a CRUD engine? Ask @maryannet what she needs.
But if you want to access psql
inside the container from the host it's a simple docker exec
command.
Makes sense. Does psql
come in the image?
It appears it does, just needs to be configured.
root@cce60a69f842:/# psql
psql: FATAL: role "root" does not exist
I can likely create a script for it then too.
docker exec -u postgres <container_name> psql
should do the trick.
That was actually run from within the container. I tried the following too:
jeff@ 🦠~/Repos/pandaid-api $ docker exec -u postgres pandaid-api_postgres_1 psql
jeff@ 🦠~/Repos/pandaid-api $ docker exec pandaid-api_postgres_1 psql
psql: FATAL: role "root" does not exist
jeff@ 🦠~/Repos/pandaid-api $
My bad - left off some flags:
$ docker exec -it -u postgres pandaid-api_postgres_1 psql
psql (11.6 (Debian 11.6-1.pgdg90+1))
Type "help" for help.
postgres=#
ah okay that worked.
Here's the equivalent command from within the container itself.
root@598b5a9195bc:/# psql -U postgres
psql (11.6 (Debian 11.6-1.pgdg90+1))
Type "help" for help.
postgres=#
Since it's already a request in this issue, I'll make it into a quick script.
Is there any preference to docker
commands vs. docker-compose
commands? They both do the same thing it seems, just need to be configured.
jeff@ 🦠~/Repos/pandaid-api $ docker-compose run --rm postgres psql -h postgres -p 5432 -U postgres
psql (11.6 (Debian 11.6-1.pgdg90+1))
Type "help" for help.
postgres=# exit
jeff@ 🦠~/Repos/pandaid-api $ docker exec -it -u postgres pandaid-api_postgres_1 psql
psql (11.6 (Debian 11.6-1.pgdg90+1))
Type "help" for help.
postgres=# exit
jeff@ 🦠~/Repos/pandaid-api $
docker-compose is simpler in the development phase - you just type docker-compose up -d
and you've got all the services up and running. It's bundled with the CookieCutter template so I don't see a need to abandon it.
Well it seems there is actually a difference. For both these psql
commands and the manage.py
from before, docker-compose run
will spin up a new container, while docker exec
will connect to an existing one. I think we actually want the docker exec
syntax.
docker-compose
looks to the service name in the docker-compose.yml
and creates it. docker
will look to a named container. But you have to make sure the container is running, by first running docker-compose up
anyway. I'm still in favor of the docker
syntax I think.
I think for now I'll make the docker
syntax the default for these scripts, but leave the docker-compose
in commented out.
A lot of these will be getting into the Docker shell and executing some command.
A current example of this is the file
/dev/manage_py.sh
- it should be moved to/dev/mac/manage_py.sh
(and an equivalent folder should be made for Windows).This makes it more convenient to do various common tasks, especially those involving getting a Docker shell. So for example, the command in manage_py.sh makes the "manage.py" functions built into Django easier to use by executing them in the Docker container:
docker-compose run --rm web "python manage.py $@"
Some convenience functions we should add:
/dev/win/manage_py.sh
that runs manage.py on a Windows computer; see the Windows instructions in the README for examples