Solution to Challenge: Running a Postgres Database
Learn the solution to the challenge you completed.
We'll cover the following
Solution
The following command will run the PostgreSQL
:
docker run \
-it --rm --name postgres \
-p 3000:5432 \
--mount "src=postgresdata,target=/var/lib/postgresql/data" \
-e POSTGRES_PASSWORD=mysecret \
postgres
-
-it
runs an interactive session. -
--rm
removes the container after the container stops. -
--name
is used to name the container aspostgres
. -
-p
is used to define both the exposed port (left side of:
) and the default port (right side of:
) on whichpostgres
is running. -
--mount
is used to define a persistent Docker volume namedpostgresdata
. -
-e
allows the setting of required environmental variables. The defaultpostgres
user is created when not defining any user and the password is set usingPOSTGRES_PASSWORD
.
π Connect the terminal to see the above command in action.
Get hands-on with 1400+ tech skills courses.