- 1 year ago
Docker Postgres with windows share
To use a Windows share with Docker and run a PostgreSQL container, you can follow these steps:
Set up the Windows share: Create a Windows share and make sure it is accessible from your Docker host machine. Ensure that the Docker host machine has proper read and write permissions to the shared folder.
Create a Docker volume: Open a command prompt or terminal and run the following command to create a Docker volume that will map to the Windows share:
cssdocker volume create --name mypgdata --opt type=cifs --opt device=//<Windows Share Path> --opt o=username=<Username>,password=<Password>
Replace
<Windows Share Path>
with the path to your Windows share,<Username>
with your Windows share username, and<Password>
with your Windows share password. This command will create a Docker volume namedmypgdata
that maps to the Windows share.Run the PostgreSQL container: Start a new PostgreSQL container and mount the Docker volume created in the previous step. Run the following command to run the container:
cssdocker run --name postgres -e POSTGRES_PASSWORD=<Password> -p 5432:5432 -v mypgdata:/var/lib/postgresql/data -d postgres
Replace
<Password>
with the desired password for the PostgreSQL database.This command will start a new PostgreSQL container named
postgres
, expose port 5432 for accessing the database, and mount themypgdata
Docker volume to the/var/lib/postgresql/data
directory inside the container.Verify the PostgreSQL container: Run the following command to check the status of the PostgreSQL container:
docker ps
You should see the
postgres
container running.
Now you have a PostgreSQL container running with data stored in the Windows share. You can connect to the PostgreSQL database using the specified port (5432) and the provided password.
Please note that using a Windows share with Docker may have performance implications and may not be suitable for production environments. It is recommended to use native Docker volumes or persistent storage options for better performance and reliability.