![]() Supported tags and respective Dockerfile links You can view the Docker Hub page for this image at ![]() Once you want to work again on your project, you can use docker-compose up again to run your database.Drupal is an open source content management platform powering millions of websites and applications.Īnd is provided by the original uploader. When you finish working on your project, I recommend you to stop the running Postgres Docker container using the command below: Stop the Docker ComposeĪs I mentioned before, one of the advantages of using Docker Compose for Postgres is to avoid background processes on your computer. You can find the connection information (the username, the password, and the default database). That's it everything is set up! To test your database, you should connect to it using the software or programming language of your choice.Īs a reminder, the Postgres database is accessible on localhost with the port 5432. In the root of your project repository, type the following command to install the dependencies and run your database: init.sql:/docker-entrypoint-initdb.d/init.sql # The init script will be executed when the database is first run # In this example, we share an init.sql script with the container env, and it should be located at the root of your repository with your Docker Compose. ![]() If you don't want to put your environment variable in your Docker Compose file, you can create an environment file at your project root. Set-up an environment file for your Postgres database These steps are not mandatory, and to keep the Postgres Docker Compose example simple, we will not use them at the tutorial end. Postgres Docker Compose configurations file ( optional)īefore running your file, I want to share with you some optional configurations. ![]() With this first version of your Postgres Docker Compose file, you will be able to run the database and connect to it! Step 2. POSTGRES_DB: default_database # The PostgreSQL default database (automatically created at first launch) POSTGRES_PASSWORD: password # The PostgreSQL password (useful to connect to the database) POSTGRES_USER: username # The PostgreSQL user (useful to connect to the database) # but take into consideration that it will change the way # Note: You are free to change your computer's port, # we must share the port with our computer's port. # If we want to access the database from our computer (outside the container), # By default, a Postgres database is running on the 5432 port. # Official Postgres image from DockerHub (we use the last version) # Note: This may change the commands you are going to use a little bit. # but you can use the name of your choice. # We use the keyword 'services' to start to create services. # For example, a service, a server, a client, a database. # You should know that Docker Compose works with services. # We use '3' because it's the last version. # A Docker Compose must always start with the version tag. Once you created the Docker Compose file, your folder architecture should be similar as below. If you don't have any project yet, you can do it in a new folder on your computer. This file is called docker-compose.yml, and you can make it at your project's root. The first step consists of creating the configuration file to run Postgres in Docker. The configuration file will be detailed line per line, so you will be able to test it and configure it for your needs. In this part, I will show you how to create a Postgres Docker Compose example. With one command, you can also shut down all the environment and free your computer from work. One command is enough to set up a Postgres database in Docker from scratch with new parameters. I'm not going to lie, I'm not constantly moving all my environments to Docker, but I like to have a part of it in a dedicated one. I like to use containers for some of my tools. One of the things I dislike the most is installing "big" tools on my computers (for example, a database engine). When I'm working on a new project, I like to have a clean environment. If you're here today, it's because you probably need it in your project! PostgreSQL is one of the most used database engines nowadays. Time to read 3m Context Why using Docker Compose to a create Postgres database This tutorial teaches you how to create a Postgres Docker Compose file. Docker-Compose with PostgreSQL ready to use
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |