12/1/2023 0 Comments Docker postgres create databaseWe can create custom variables or define values for those that are available for the image we are using. env file with the variables that you want to pass to the container:ĬOMPOSE_PROJECT_NAME=springbootpostgresflyway You can learn more about this in the Docker documentation on variable substitution. I’m going to define the environment variables that are used in the Compose file. You can specify this property according to your needs. The default restart policy is no, and this service won’t be restored automatically in case of a failure or when I reboot my computer. I want to launch this container manually, only when I’m working on this project. I didn’t establish any restart config nor restart policy in my example. You can provide only keys for those values that you want to keep secret, as is stated in the docs:Įnvironment variables with only a key are resolved to their values on the machine Compose is running on, which can be helpful for secret or host-specific values. We define all environment variables that will be used by the container. All named volumes have to be declared in the root level of the docker-compose.yml file, hence in the end I put the following lines: Line 9 contains the name of the volume and the path where the directory is mounted in the container. Docker will create and manage a directory on the host file system ( /var/lib/docker/volumes/ on Linux) and use it as the source for the /var/lib/postgresql/data on the container. To designate a directory that will be used to keep the database content on my machine I need the volumes option. For this reason, we recommend always explicitly specifying your port mappings as strings. YAML parses numbers in the format xx:yy as a base-60 value. I also wrote the port mapping in a string as it’s recommended to avoid errors in case using container port lower than 60: You can find details in the compose docs:Įither specify both ports ( HOST:CONTAINER), or just the container port (an ephemeral host port is chosen). You map container ports to the ports on the host. The image description contains also the list of all variables than can be specified for the service. You can find all available tags on the image page. The postgres service is going to be built from an official PostgreSQL Docker image. Let’s take a look at the properties configured in the docker-compose.yml file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |