我试图从我的docker-compose设置基本的postgres信息.容器启动但是当我运行docker-compose时,不会覆盖来自Dockerfile的变量.请帮忙.
FROM mine/debian7
## START: UPDATES & INSTALLS ###########################################################################################
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main" >> /etc/apt/sources.list.d/pgdg.list && \
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add - && \
apt-get update && \
apt-get upgrade && \
apt-get install -y python-software-properties software-properties-common postgresql-9.4 postgresql-client-9.4 postgresql-contrib-9.4 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
## END: UPDATES & INSTALLS #############################################################################################
ENV DB_USER_NAME test
ENV DB_PASSWORD test
ENV DB_NAME test
## START: CONCFIGURATION ###############################################################################################
# start postgres at boot
#RUN echo "/etc/init.d/postgresql start" >> ~/.bashrc
USER postgres
RUN /etc/init.d/postgresql start && \
psql --command "CREATE USER $DB_USER_NAME WITH SUPERUSER PASSWORD '$DB_PASSWORD';" && \
createdb -O $DB_NAME $DB_NAME
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.4/main/pg_hba.conf
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.4/main/postgresql.conf
VOLUME ["/etc/postgresql","/var/log/postgresql","/var/lib/postgresql"]
#USER root
#RUN update-rc.d postgresql defaults
## END: CONCFIGURATION #################################################################################################
EXPOSE 5432
CMD service postgresql start && tail -f /var/log/postgresql/postgresql-9.4-main.log
还有我的docker-compose文件:
tomcat:
image: clegge/tomcat
ports:
- "8080:8080"
volumes:
- sample.war:/opt/tomcat7/webapps/sample.war
postgres:
build: /Users/clegge/Dockers/docker-postgres-base/
ports:
- "5432:5432"
stdin_open: true
tty: true
environment:
- DB_USER_NAME=legge_crud
- DB_PASSWORD=legge_crud
- DB_NAME=test
我错过了什么?
在Dockerfile中,您可以在RUN语句中使用该环境变量.这些是在构建图像时在构建期间执行的.
当您使用docker run启动容器时,它只会根据您刚刚构建的映像启动容器.此时的图像已存在,并且不再执行RUN语句.
因此,在运行时设置这些环境变量将不起作用.