Let's perform the following steps to get the logs from the application running inside a container:
- While you are in a shell, connect to the PostgreSQL database named postgresdb using the username testuser. You will see the PostgreSQL prompt, as follows:
$ psql --username testuser postgresdb
psql (12.1 (Debian 12.1-1.pgdg100+1))
Type "help" for help.
- While on the PostgreSQL prompt, use the following command to create a table and add some data to it:
CREATE TABLE test ( id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, a int NOT NULL, created_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP ); INSERT INTO test (a) SELECT * FROM generate_series(-1, -1000, -1);
- Get the log's configuration details frompostgresql.conf. You will see that the logs are stored in the /var/log/postgresql directory:
$ cat /var/lib/postgresql/data/postgresql.conf |grep log
- List and access the logs in the /var/log/postgresql directory:
$ ls /var/log/postgresql
- Optionally, while you're inside the container, you can create a backup of our example postgresdb database in the tmp directory using the following command:
$ pg_dump --username testuser postgresdb > /tmp/backup.sql
With that, you have learned how to get shell access into a container and how to access the locally stored logs and files inside the container.