Start to develop with Docker¶
How to run the instance for development¶
There are two options to develop using Docker containers:
Alternative A: Running by command line and editing the code using your preferred editor (usually harder).
Alternative B: Using the vscode remote containers extension (easier).
Alternative A: Building and running Docker for development¶
Build (first time only):
docker-compose --project-name geonode -f docker-compose.yml -f .devcontainer/docker-compose.yml build
docker-compose --project-name geonode -f docker-compose.yml -f .devcontainer/docker-compose.yml up
If you are running
tomcat9 services, you need to stop them,
docker-compose will take care of running the database and geonode service.
Otherwise, you will get the following error:
ERROR: for db Cannot start service db: driver failed programming external connectivity on endpoint db4geonode: Error starting userland proxy: listen tcp4 0.0.0.0:5432: bind: address already in use ERROR: Encountered errors while bringing up the project.
Running the geonode application in debug mode:
docker exec -it django4geonode bash -c "python manage.py runserver 0.0.0.0:8000"
When running, you can debug the application using your preferred method.
For example, you can edit a file, save it and see your modifications.
You can also use ipdb to add breakpoints and inspect your code
import ipdb; ipdb.set_trace() in the line you want your breakpoint).
Another option is to use debugpy alongside with vscode, for this you have to enable debugpy inside your django4geonode container:
docker exec -it django4geonode bash -c "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 manage.py runserver 0.0.0.0:8000 --nothreading --noreload"
Select “Run and Debug” in vscode and use the following launch instruction in your
Alternative B: Using vscode extension¶
Alternatively, you can develop using the vscode remote containers extension. In this approach you need to:
Install the extension in your vscode: ms-vscode-remote.remote-containers
On your command pallet, select: “Remote-Containers: Reopen in Container”
If it’s the first time, vscode will take care of building the images. This might take some time.
Then a new vscode window will open, and it’ll be connected to your docker container.
The message “Dev Container: Debug Docker Compose” will appear in the bottom-left corner of that window.
In the vscode terminal, you’re going to see something similar to
To run your application, you can use the integrated terminal (
./manage.py runserver 0.0.0.0:8000) or the vscode “Run and Debug” option. For launching with “Run and Debug”, use the following instruction file:
For more information, take a read at vscode remote containers help page.