Categories
Containerisation Django Docker Python

Create a Django admin account inside a Docker container

Assuming that your Django container is already running under Docker, find out what it’s ‘Container ID’ is.

$ docker ps
CONTAINER ID IMAGE ...
fb3aabc8e123 django-web ...

In the above example the Container ID is fb3aabc8e123.

Now you can easily execute commands inside that container.

$ docker exec -it fb3aabc8e123 sh

The ‘-it’ option executes the command in an Interactive Terminal.

The ‘sh’ at the end of the command is the program to run, in this case it the system shell program. You could use ‘bash’ on a Linux machine if that’s your preference.

Now that you have a shell running in the Django container, you can run the command to create the admin user account.

# python ./manage.py createsuperuser

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.