Step 3: Start docker container in detached mode and persist data on postgres image by creating a volume and binding it to a destination Step 2: Download postgres docker image: docker pull postgres:latest Step 1: Start powershell in non-admin mode Here is the detailed overview of the entire process I followed on Windows 10 powershell (commands are the same in Linux and macOS as well): Steps 3, 5, 6, 7, and 8 answer your question directly. If you don't have persistent data, you will have to repeat everything you did the first time. To do this, you will have to persist data on the postgres image. I'm assuming that you want to be able to view data present in your container everytime you connect to it from outside. So you're accessing the database (which is running in docker on a server) from your localhost. Template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres Postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 | Mytest | postgres | UTF8 | en_US.utf8 | en_US.utf8 | Name | Owner | Encoding | Collate | Ctype | Access privileges (password mysecretpassword) postgres=# \l ![]() psql -h public-ip-server -p 5432 -U postgres Go to your localhost (where you have some tool or the psql client). Go inside your container and create a database: docker exec -it 05b3a3471f6f psql -U postgres Run the postgres database (command above) docker psĬONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESÄ 5b3a3471f6f postgres "/docker-entrypoint.s" 1 seconds ago Up 1 seconds 0.0.0.0:5432->5432/tcp some-postgres So now your postgres is accessible from your public-server-ip:5432 So now you have mapped the port 5432 of your container to port 5432 of your server. You can run Postgres this way (map a port): docker run -name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |