Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

any plan to support native windows container postgres image #324

Open
satyapal88 opened this issue Aug 11, 2017 · 8 comments · May be fixed by #506
Open

any plan to support native windows container postgres image #324

satyapal88 opened this issue Aug 11, 2017 · 8 comments · May be fixed by #506
Labels
Request Request for image modification or feature

Comments

@satyapal88
Copy link

No description provided.

@tianon
Copy link
Member

tianon commented Aug 11, 2017

No current plans, but it's probably something worth considering.

Looking at https://www.postgresql.org/download/windows/, we should probably use either the installers provided by EnterpriseDB (or just use the raw ZIP archives, since we don't actually need it registered as a service or anything else the installer will likely end up doing for us).

@tianon
Copy link
Member

tianon commented Sep 15, 2017

I've played with this a little bit today, and here's my current Dockerfile:

FROM microsoft/windowsservercore

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]

# PATH isn't actually set in the Docker image, so we have to set it from within the container
RUN $newPath = ('C:\PostgreSQL\bin;{0}' -f $env:PATH); \
	Write-Host ('Updating PATH: {0}' -f $newPath); \
	[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine);
# doing this first to share cache across versions more aggressively

# https://www.enterprisedb.com/download-postgresql-binaries
ENV PG_VERSION 9.6.5-1

RUN $url = ('https://get.enterprisedb.com/postgresql/postgresql-{0}-windows-x64.exe' -f $env:PG_VERSION); \
	Write-Host ('Downloading {0} ...' -f $url); \
	Invoke-WebRequest -Uri $url -OutFile 'pgsql.exe'; \
	\
	Write-Host 'Extracting ...'; \
	Start-Process pgsql.exe -Wait \
		-ArgumentList @( \
# https://www.enterprisedb.com/docs/en/9.3/pginstguide/PostgreSQL_Installation_Guide-12.htm
			'--mode', 'unattended', \
			'--unattendedmodeui', 'none', \
			'--extract-only', 'yes', \
			'--prefix', 'C:\PostgreSQL' \
		); \
	\
	Write-Host 'Installing ...'; \
	Start-Process C:\PostgreSQL\installer\vcredist_x64.exe -Wait \
		-ArgumentList @( \
			'/install', \
			'/passive', \
			'/norestart' \
		); \
	\
	Write-Host 'Verifying install ...'; \
	Write-Host '  postgres --version'; postgres --version; \
	Write-Host '  psql --version'; psql --version; \
	\
	Write-Host 'Removing ...'; \
	Remove-Item @( \
			'C:\PostgreSQL\StackBuilder', \
			'C:\PostgreSQL\doc', \
			'C:\PostgreSQL\include', \
			'C:\PostgreSQL\installer', \
			'C:\PostgreSQL\pgAdmin*', \
			'pgsql.exe' \
		) -Recurse -Force; \
	\
	Write-Host 'Complete.';

# if this is a volume, "initdb" can't change the permissions of it in the way it needs to
#ENV PGDATA C:\\pgdata ??
#VOLUME $PGDATA

# TODO docker-entrypoint.ps1 ? (for initdb and "docker run <image> --flag --flag --flag")

EXPOSE 5432
CMD ["postgres"]

It builds successfully and I can run PostgreSQL commands (like postgres --version, initdb, etc). However, no matter what I try, when I run simply postgres to try to start the server, it has no output, and after a short time simply exits (and checking the process list shows that it doesn't leave anything running in the background either).

Edit: note to self -- I ended up using the installer instead of the zip file because the installer includes the necessary vcredist installer, and the zip file does not.

(If we can get it working, my current plan for update.sh to fetch the appropriate value for PG_VERSION here is likely to scrape https://www.enterprisedb.com/download-postgresql-binaries to get https://www.enterprisedb.com/postgresql-965-binaries-win64 since the version number of the .zip files should match the .exe files, and they seemed easier to scrape since the .exe file selector page uses AJAX / JavaScript to dynamically change the page.)

@WalternativE
Copy link

I played around with the creation of a PostgreSQL container based on the windowsservercore image as well. I built it using the installer by EnterpriseDB from the start, installed it as a service and used the old Wait-Service script to keep the container up and running referenced in this IIS container issue microsoft/iis-docker#1 (they moved to a custom service monitor for this but the script works fine for dev purposes).

I ran into the same problems using volumes - even manually it is almost impossible changing the NTFS permissions in a way that the initdb process exits with success. I tried to force the container to run as another user than containeradministrator but it seems that the USER statement in windows container dockerfiles still doesn't work as one would suspect (at least I am not able to use it correclty it seems). There seems to be an option to run a container as "NT AUTHORITY\SYSTEM" and volumes as well as subfolders created in them at least appear to give this user full access by default - I've yet not managed to test this out successfully. Here is the link to the gist of the WIP Dockerfile if this is any help https://gist.github.com/WalternativE/b2c4ed32894f427ef8a85e921cfa2bbd .

@StefanScherer
Copy link

I tried the postgres ZIP file today and downloaded the Visual C++ 2013 Redistributable Package from Microsoft:

https://github.com/StefanScherer/dockerfiles-windows/blob/c4d98675d9d96d4ed98324b92f61b76fdced28d7/postgres/Dockerfile#L11-L13

The binaries seem to work both in windowsservercore and nanoserver, but I only tried the --help option to check if the binaries output something.

@wglambert wglambert added the Request Request for image modification or feature label Apr 25, 2018
@somashekarg
Copy link

Hi,
I have created the container for postgres in windows docker and i have used the dockerfile below

FROM microsoft/windowsservercore:10.0.14393.1944 AS download

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

ENV PG_VERSION 10.1-3

RUN Invoke-WebRequest $('https://get.enterprisedb.com/postgresql/postgresql-{0}-windows-x64-binaries.zip' -f $env:PG_VERSION) -OutFile 'postgres.zip' -UseBasicParsing ;
Expand-Archive postgres.zip -DestinationPath C:\ ;
Remove-Item postgres.zip

RUN Invoke-WebRequest 'http://download.microsoft.com/download/0/5/6/056DCDA9-D667-4E27-8001-8A0C6971D6B1/vcredist_x64.exe' -OutFile vcredist_x64.exe ;
Start-Process vcredist_x64.exe -ArgumentList '/install', '/passive', '/norestart' -NoNewWindow -Wait ;
Remove-Item vcredist_x64.exe

FROM microsoft/nanoserver:10.0.14393.1944

COPY --from=download /pgsql /pgsql
COPY --from=download /windows/system32/msvcp120.dll /pgsql/bin/msvcp120.dll
COPY --from=download /windows/system32/msvcr120.dll /pgsql/bin/msvcr120.dll

RUN setx /M PATH "C:\pgsql\bin;%PATH%"

EXPOSE 5432
CMD ["postgres"]

But the container is not starting
how to start the container and how to get the connection string ?
how to connect using pgadmin from the host machine?

@tianon
Copy link
Member

tianon commented Oct 2, 2018

See #506 for an approach which uses BigSQL and multi-stage builds to create something based on Nano Server that's not acceptable for the constraints of an official image, but may be useful/interesting to other folks following this thread. 👍

@peetw
Copy link

peetw commented Oct 3, 2018

We managed to get a PostgreSQL 9.6 server working in a container on Windows using the following Dockerfile:

https://gist.github.com/peetw/10f49281423753d068f62bf47ba4642f

This can then be built and run with the following commands:

docker build -t postgres:9.6.10 .
docker run -d -p 5432:5432 postgres:9.6.10

You can then connect to it as normal from the host running the container, i.e.:

psql -h localhost -p 5432 -d postgres

@ta32
Copy link

ta32 commented Dec 14, 2018

Hi i am a docker noob but here's my version of creating a docker postgres windows container. Is using chocolaty cheesy? Although i might want to lock in the version. Currently they only have postgres 10.4

FROM microsoft/windowsservercore

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]

RUN Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN choco feature enable --name=allowGlobalConfirmation
RUN choco install postgresql10 --params '/Password:postgres'

# also available in the aspnet-docker image
RUN Invoke-WebRequest -UseBasicParsing -Uri 'https://dotnetbinaries.blob.core.windows.net/servicemonitor/2.0.1.3/ServiceMonitor.exe' -OutFile 'ServiceMonitor.exe'

COPY ["pg_hba.conf", "c:/Program Files/PostgreSQL/10/data"]
SHELL ["cmd"]
RUN setx /M PATH "C:\\Program Files\\PostgreSQL\\10\\bin;%PATH%"

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]

COPY docker-entrypoint.cmd "C:\\"
ENTRYPOINT ["C:\\docker-entrypoint.cmd"]

EXPOSE 5432
# mointor this service
CMD ["postgresql-x64-10"]

This is the entry-point script - i guess it could do more things

@echo off
SETLOCAL EnableDelayedExpansion
where postgres
echo "check running services"
net start
call ServiceMonitor.exe %*

edit: I found this repo https://hub.docker.com/r/kiazhi/nanoserver.postgresql
last commit was 2 years ago, would be great for postgres to maintain a nano server image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Request Request for image modification or feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants