본문 바로가기
DevOps/Docker

Postgres with docker-compose

by sayshare 2023. 7. 23.
반응형

What is docker compose file?

Docker compose file allows us to predefined images name and their properties to be pulled from the docker registry and run locally. In order to pull a docker image using the docker-compose file, we need to install the docker desktop on the local machine to use the docker command and view all the pulled images. 

Create Docker Compose

First, we need to navigate into the project folder and create a file named docker-compose.yml

> cd project_folder

> touch docker-compose.yml

docker-compose.yml


  
services:
postgres:
container_name: postgres
image :
postgresenvironment:
POSTGRES_USER: ${USERNAME}
POSTGRES_PASSWORD : ${PASSWORD}
PGDATA : /data/ postgres
ports :
- "5432:5432"
restart : unless-stopped

 

Run the command to pull docker image:

> docker compose up -d

 

After pulling the PostgreSQL image, we can connect to the PostgreSQL database via pre-defined properties.

 

반응형