我使用了以下命令,并在Ubuntu os中为postgresql创建了一个docker容器。无论如何,我可以在Run命令中指定postgres db密码,并从docker容器内的sql脚本执行sql命令吗?
目前我使用以下命令访问容器并手动执行sql命令。
sudo docker run --rm -t -i --link pg_docker:pg postgresql_image bash
sql -h $PG_PORT_5432_TCP_ADDR -p $PG_PORT_5432_TCP_PORT -d docker -U docker --password
prompts for postgres Password:
# example Dockerfile for http://docs.docker.com/examples/postgresql_service/
#
FROM ubuntu
MAINTAINER vicky
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN apt-get update && apt-get install -y python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
USER postgres
RUN /etc/init.d/postgresql start &&\
psql --command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" &&\
createdb -O docker docker
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf
EXPOSE 5432
VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
Commands to Create Docker Image & Container
sudo docker build -t postgresql_image .
sudo docker run --rm -P --name pg_docker postgresql_image &
sudo docker run --rm -t -i --link pg_docker:pg postgresql_image bash
sql -h $PG_PORT_5432_TCP_ADDR -p $PG_PORT_5432_TCP_PORT -d docker -U docker --password
prompts for postgres Password:
答案 0 :(得分:1)
dockerhub中有一个正式的postgre图像(https://registry.hub.docker.com/_/postgres/)
,提供
1)在Run命令
中指定postgres db密码2)使用run命令时执行sql命令。
如果它满足您的要求,请告知我们