This guide assumes the following:
- The Oracle Database runs on a Docker container named axer and is attached to the Docker network axer_network.
- The devcontainer is attached to the Docker network axer_network
Name | Value | Remarks |
---|---|---|
PROJECT_ROOT | /home/oracledev/vscode-remote-oradev-python | Direcotry where this repository was cloned to. |
DB_CONTAINER_NAME | axer | Name of the Oracle Database Docker container. |
DOCKER_NETWORK | axer_network | Name of the Docker network. Both the database and devcontainer are attached to this network. |
DB_PORT | 1521 | Database port |
DB_USERNAME | pydev | Example database username. |
DB_PASSWORD | pydev123 | Example database password. |
WALLET_NAME | pydev_wallet | Name for the wallet. |
WALLET_PASSWORD | Oracle1# | Password for the wallet. |
On the host system:
- Set the environment variables and working directory:
$ PROJECT_ROOT=/home/oracledev/vscode-remote-oradev-python $ DB_CONTAINER_NAME=axer $ DB_PORT=1521 $ DB_USERNAME=pydev $ DB_PASSWORD=pydev123 $ WALLET_NAME=pydev_wallet $ WALLET_PASSWORD=Oracle1# $ cd $PROJECT_ROOT
- Create a Bash session on the database container.
$ docker exec -it -u oracle -w /home/oracle \ > -e DB_CONTAINER_NAME=$DB_CONTAINER_NAME \ > -e DB_PORT=$DB_PORT \ > -e DB_USERNAME=$DB_USERNAME \ > -e DB_PASSWORD=$DB_PASSWORD \ > -e WALLET_NAME=$WALLET_NAME \ > -e WALLET_PASSWORD=$WALLET_PASSWORD \ > $DB_CONTAINER_NAME bash
- (In the database container) Set the Oracle environment variables:
[oracle@044eeee405b9 /]$ ORAENV_ASK=NO && ORACLE_SID=XE && . oraenv The Oracle base remains unchanged with value /opt/oracle
- Create a new wallet:
[oracle@044eeee405b9 /]$ (echo "$WALLET_PASSWORD"; echo "$WALLET_PASSWORD") | mkstore -wrl "$HOME/$WALLET_NAME" -create
- Create a database credential entry using either methods of specifying the Easy Connect string:
[oracle@044eeee405b9 /]$ echo "$WALLET_PASSWORD" | mkstore -wrl "$HOME/$WALLET_NAME" -createCredential $DB_CONTAINER_NAME:$DB_PORT/XEPDB1 $DB_USERNAME $DB_PASSWORD
- Check that the credentials were successfully added:
[oracle@044eeee405b9 /]$ echo $WALLET_PASSWORD | mkstore -wrl "$HOME/$WALLET_NAME" -listCredential
- Logout of the database container.
[oracle@044eeee405b9 /]$ exit
- Create a
.wallets
directory and copy the wallet directory and contents:$ mkdir .wallets && docker cp $DB_CONTAINER_NAME:/home/oracle/$WALLET_NAME .wallets
- Create a
sqlnet.ora
file in thePROJECT_ROOT
:$ cat << EOF > sqlnet.ora WALLET_LOCATION = (SOURCE = (METHOD = FILE) (METHOD_DATA = (DIRECTORY = .wallets/$WALLET_NAME) ) ) SQLNET.WALLET_OVERRIDE = TRUE EOF
When executing the Python code, set the TNS_ADMIN
environment variable to the directory where the sqlnet.ora
file is located. It is important to note that when running the code within the devcontainer, the PROJECT_ROOT
is mounted and the current working directory is set to typically a path like /workspace/vscode-remote-oradev-python
. The leaf of the workspace path follows the name of the running devcontainer name.
When debugging code, add the following attributes to the launch.json
file, and update DB_HOST
(set to the DB_CONTAINER_NAME
when working with a database container), DB_PORT
and DB_SERVICE_NAME
accordingly:
"env": {
"TNS_ADMIN": "${cwd}",
"DB_HOST": "axer",
"DB_PORT": "1521",
"DB_SERVICE_NAME": "XEPDB1"
}