docker ps -a
docker pull postgres
docker build -t postgres .
docker exec -it postgres psql -U postgres
docker container run -it --rm -p 6666:5432 --name postgres postgres
\list
or \l
: list all databases
\dt
: list all tables in the current database
You will never see tables in other databases, these tables aren't visible. You have to connect to the correct database to see its tables (and other objects).
To switch databases:
\connect database_name
See the manual about psql.
From https://dba.stackexchange.com/questions/1285/how-do-i-list-all-databases-and-tables-using-psql#1288
docker pull mongo
docker build -t mongo .
docker container run -it --rm -p 5555:27017 --name mongo mongo
docker exec -it mongo mongo
use my-new-db-name
- create user
db.users.save( {username:"my-user"} )
http://www.mkyong.com/mongodb/how-to-create-database-or-collection-in-mongodb/
docker exec -d 0a9e85052493 bash
docker rm $(docker ps -q -f status=exited)
see https://forums.docker.com/t/cant-delete-image-with-children/16667/4
open your terminal and enter :
docker inspect --format=’{{.Id}} {{.Parent}}’ $(docker images --filter since=<image_id> -q)
where you replace <image_id> by your image id (Yeah, man, obviously)
It will kill every children
then , write :
docker rmi <image_id>
if it tell you that it is link to a docker so remove it too with the command :
docker rm < docker_id>
and then go back to point 2) to end the process .
You can acces http://127.0.0.1:1337/
from browser ? But the front App CAN NOT ?
Docker container has its own network IPs, including its own localhost.
In the current situation The stack is (api(sailjs) + db(postgres) + app(Universal React Next)). All of them are in dedicated docker containers. All the containers are behind a 4th one named server, working as a proxy.
So when APP fetches API server side, it does in in the docker network.
This is why you can acces http://127.0.0.1:1337/
from browser (front)? But the front App CAN NOT (because the fetch is server side) ?
- List containers
docker ps -a
- Inspect the API
docker container inspect <container_id>
- Get the
Gateway": "172.21.0.1"
which is the"IPAddress": "172.21.0.5"
where the last bit is replaced by 1 - Fetch on Gatewy - React example
const res = await fetch('http://172.21.0.1:9999/api/user')