Skip to content

Instantly share code, notes, and snippets.

@rac021
Last active November 12, 2017 16:00
Show Gist options
  • Save rac021/762c5e798793ce8e012fbe3aedb50668 to your computer and use it in GitHub Desktop.
Save rac021/762c5e798793ce8e012fbe3aedb50668 to your computer and use it in GitHub Desktop.
ONLINE DOCKER PLAY :
http://host2.labs.play-with-docker.com/p/b0f9134f-8b4c-4a95-b2f5-786b62acbbf7#b0f9134f_node1
This exemple is based on redmine container.
1- Fire up the postgres database container :
docker run -d --name test-postgres -e POSTGRES_PASSWORD=secret -e POSTGRES_USER=redmine postgres
2- Fire up redmine container and pass the postgres container using --link :
docker run -d --name my-redmine --link test-postgres:postgres redmine
Test :
$ docker exec -it my-redmine bash
$ env | grep POSTGR
=========================================================================
Connect to an existing postgres database using docker-compse + volums :
postgres9:
image: postgres:9.6
ports:
- 6981:5432
restart: on-failure:3
user: postgres
volumes_from:
- pg_data
environment:
POSTGRES_PASSWORD: yahiaouii
POSTGRES_USER: ryahiaouii
PGDATA : /var/lib/postgresql/9.6/main
pg_data:
image: alpine:latest
volumes:
- /var/lib/postgresql/9.6/main:/var/lib/postgresql/9.6/main
command: "true"
=========================================================================
docker volume create --name postgres_data
docker run --rm --name my_postgres_container --user postgres \
-e POSTGRES_PASSWORD=ryahiaoui \
-v postgres_data:/var/lib/postgresql/9.6/main \
-v postgres_data:/etc/postgresql \
-v postgres_data:/var/lib/postgresql \
-p 6981:5432 -d postgres:9.6
docker run -it --link my_postgres_container:postgres --rm postgres:9.6 \
sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" \
-p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'
psql -h localhost -p 5432 -U postgres
-------------------------------
sudo chmod a+rwx -R /var/lib/postgresql/9.6/main/
dpkg-reconfigure locales
--> add postgresql.conf : sudo cp /var/lib/postgresql/9.6/main/postgresql.auto.conf /var/lib/postgresql/9.6/main/postgresql.conf
--> sudo chown -R postgres:postgres /var/lib/postgresql/9.6/main/postgresql.conf
--> Add files : pg_hba.conf ? https://github.com/abevoelker/docker-postgres/blob/master/pg_hba.conf.default
--> sudo chown -R postgres:postgres /var/lib/postgresql/9.6/main/pg_hba.conf
sudo touch /var/lib/postgresql/9.6/main/pg_hba.conf
sudo gedit /var/lib/postgresql/9.6/main/pg_hba.conf
sudo chown -R postgres:postgres /var/lib/postgresql/9.6/main/pg_hba.conf
sudo -u postgres psql
ALTER USER postgres WITH PASSWORD 'root' ;
RUN localedef -i fr_FR -c -f UTF-8 -A /usr/share/locale/locale.alias fr_FR.UTF-8
ENV LANG fr_FR.utf8
update-locale LC_ALL=fr_FR.UTF-8 LANG=fr_FR.UTF-8 ??
****************************************************************
pg_lsclusters
pg_dropcluster --stop 9.6 main
pg_createcluster --locale fr_FR.UTF-8 --start 9.6 main
****************************************************************
docker run --rm --name my_postgres_container --user postgres -e POSTGRES_PASSWORD=ryahiaoui -v /var/lib/postgresql/9.6/main:/var/lib/postgresql/data -p 6981:5432 -d postgres:9.6 ?? fjudith/postgres-fr
docker run --rm --name my_postgres_container -e POSTGRES_PASSWORD=ryahiaoui -v /var/lib/postgresql/9.6/main:/var/lib/postgresql/data --user postgres -d postgres:9.6 ?? fjudith/postgres-fr
docker run --privileged=true -i --user postgres --rm --name my_postgres_container -e POSTGRES_PASSWORD=ryahiaoui -v /var/lib/postgresql/9.6/main:/var/lib/postgresql/data postgres:9.6 ?? fjudith/postgres-fr
ryahiaoui@ORL-5CB3410DK4:~/Bureau/Docker_pPstgres$ docker run --privileged=true -i --user postgres --rm --name my_postgres_container -e POSTGRES_PASSWORD=ryahiaoui -v /var/lib/postgresql/9.6/main:/var/lib/postgresql/data:Z postgres:9.6 ?? fjudith/postgres-fr
LOG: could not open configuration file "/var/lib/postgresql/data/postgresql.conf": Permission denied
FATAL: configuration file "/var/lib/postgresql/data/postgresql.conf" contains errors
***********
ryahiaoui@ORL-5CB3410DK4:~/Bureau/Docker_pPstgres$ sudo -u postgres psql
psql: FATAL: n'a pas pu ouvrir le fichier de correspondance des relations « global/pg_filenode.map » : Permission non accordée
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
docker volume create --name postgres_data
docker run --rm --name my_postgres_container --user postgres \
-e POSTGRES_PASSWORD=ryahiaoui \
-v postgres_data:/var/lib/postgresql/data \
-p 6981:5432 -d postgres:9.6
docker run --rm --name my_postgres_container_1 --user postgres \
-e POSTGRES_PASSWORD=ryahiaoui \
-v postgres_data:/var/lib/postgresql/data \
-p 6982:5432 -d postgres:9.6
docker run --user postgres --name service_013 --rm --link my_postgres_container:postgres postgres:9.6 \
sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" \
-p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres password=ryahiaoui'
docker run -it --link my_postgres_container_1:postgres --rm postgres:9.6 \
sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" \
-p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'
----------------------------------------------------------------------------------
Docker Compose
version: "2"
services:
postgres9 :
image : postgres:9.6
container_name: "pg-dev"
ports :
- 6981:5432
restart : on-failure:1
environment :
POSTGRES_PASSWORD : yahiaoui
user : postgres
volumes_from :
- pg_data
links :
- pg_data:postgres
#pg_data :
# image : postgres:9.6
# container_name: "pg-volume"
# volumes :
# - /var/lib/postgresql/data
# environment :
# POSTGRES_PASSWORD : yahiaoui
pg_data :
image : postgres:9.6
container_name: "pg-volume"
volumes :
- my-data-volume:/var/lib/postgresql/data
environment :
POSTGRES_PASSWORD : yahiaoui
volumes :
my-data-volume :
driver : "local"
# docker run --network=dockerppstgres_default --user postgres -it -p 6983:5432 -v dockerppstgres_my-data-volume:/var/lib/postgresql/data --rm postgres:9.6 bash
# docker run --network=dockerppstgres_default -it --link pg-volume:postgres --rm fjudith/postgres-fr bash
--------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------
DOCKER REX-RAY VOLUME PLUGIN INSTALL :
docker plugin install --grant-all-permissions rexray/ebs:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment