因此,我已经从ubuntu服务器上的dockerfile远程构建并运行了一个postgres容器。该容器似乎已启动并正在运行,我可以从ubuntu上的psql访问数据库。但是我希望能够通过PGadmin在公司网络上远程连接到数据库,到目前为止,我不得不这样做。我对Docker和Linux都非常陌生,非常感谢您的帮助。
以下是docker ps的结果:
这是dockerfile的代码:
FROM base.img:latest
RUN apt-get install postgresql postgresql-contrib -y
# Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed``
USER postgres
# Copy the dump of table to container
ADD history.dump.2015 /tmp/
# Create a PostgreSQL role named ``docker`` with ``docker`` as the password and
# then create a database `docker` owned by the ``docker`` role.
# Note: here we use ``&&\`` to run commands one after the other - the ``\``
# allows the RUN command to span multiple lines.
RUN /etc/init.d/postgresql start &&\
# psql --command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" && createdb -O docker docker
psql --command "ALTER USER postgres WITH PASSWORD 'abcdefg';"
# Adjust PostgreSQL configuration so that remote connections to the
# database are possible.
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.5/main/pg_hba.conf
# And add ``listen_addresses`` to ``/etc/postgresql/9.5/main/postgresql.conf``
RUN echo "listen_addresses='*'" >> /etc/postgresql/9.5/main/postgresql.conf
# Expose the PostgreSQL port
EXPOSE 5432
# Set the default command to run when starting the container
CMD ["/usr/lib/postgresql/9.5/bin/postgres", "-D", "/var/lib/postgresql/9.5/main", "-c", "config_file=/etc/postgresql/9.5/main/postgresql.conf"]