![]() Now join your application container to the same network: Start your Postgres container with a connection to the network by using the -network flag with docker run: This avoids binding the Postgres server's port and potentially exposing the service to your host's wider network. Use this to quickly interact with your database from a PostgreSQL shell within the container.ĭocker exec -it postgres psql -U postgres Connecting From Other Docker ContainersĬreating a Docker network is the preferred way to access PostgreSQL from other containers on the same host. The Docker image also includes the psql binary which you can invoke with docker exec. Without one you'll use your data when the container stops. You should use a volume to store your database outside the container. A named volume called postgres is referenced Docker will either create it or reattach the volume if it already exists. The -v flag is used to mount a Docker volume to the PostgreSQL container's data directory. The username defaults to postgres but can be changed by setting the POSTGRES_USER environment variable. This defines the password which will be assigned to Postgres' default superuser account. ![]() You must supply a value for the POSTGRES_PASSWORD environment variable. ![]() Start a PostgreSQL container using the docker run command: You're free to select a different version to suit your requirements. Tag which provides PostgreSQL 14 atop Bullseye. ![]() Alpine, Debian Stretch, and Debian Bullseye are offered.įor the purposes of this tutorial, we'll use the postgres :14 Tags let you select between major PostgreSQL versions from v9 to v14 and choose the operating system used as the base image. PostgreSQL has an official image on Docker Hub which is available in several different variants. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |