Fix code block formatting and add tabs

This commit is contained in:
Sébastien DIDIER 2023-08-24 10:28:23 +02:00
parent 1173635cf2
commit 9bdecfc637
1 changed files with 51 additions and 13 deletions

View File

@ -35,16 +35,36 @@ $ docker network create postgresnet
Now you can run PostgreSQL in a container and attach to the volume and network that you created above. Docker pulls the image from Hub and runs it for you locally. Now you can run PostgreSQL in a container and attach to the volume and network that you created above. Docker pulls the image from Hub and runs it for you locally.
In the following command, option `--mount` is for starting the container with a volume. For more information, see [Docker volumes](../../storage/volumes.md). In the following command, option `--mount` is for starting the container with a volume. For more information, see [Docker volumes](../../storage/volumes.md).
```console {{< tabs >}}
$ docker run --rm -d --mount \ {{< tab name="Mac / Linux" >}}
"type=volume,src=db-data,target=/var/lib/postgresql/data" \
-p 5432:5432 \ ```console
--network postgresnet \ $ docker run --rm -d \
--name db \ --mount type=volume,src=db-data,target=/var/lib/postgresql/data \
-e POSTGRES_PASSWORD=mysecretpassword \ -p 5432:5432 \
-e POSTGRES_DB=example \ --network postgresnet \
postgres --name db \
``` -e POSTGRES_PASSWORD=mysecretpassword \
-e POSTGRES_DB=example \
postgres
```
{{< /tab >}}
{{< tab name="Windows" >}}
```powershell
$ docker run --rm -d `
--mount type=volume,src=db-data,target=/var/lib/postgresql/data `
-p 5432:5432 `
--network postgresnet `
--name db `
-e POSTGRES_PASSWORD=mysecretpassword `
-e POSTGRES_DB=example `
postgres
```
{{< /tab >}}
{{< /tabs >}}
Now, make sure that your PostgreSQL database is running and that you can connect to it. Connect to the running PostgreSQL database inside the container. Now, make sure that your PostgreSQL database is running and that you can connect to it. Connect to the running PostgreSQL database inside the container.
@ -90,9 +110,10 @@ You'll need to clone a new repository to get a sample application that includes
? What version of Python do you want to use? 3.11.4 ? What version of Python do you want to use? 3.11.4
? What port do you want your app to listen on? 5000 ? What port do you want your app to listen on? 5000
? What is the command to run your app? python3 -m flask run --host=0.0.0.0 ? What is the command to run your app? python3 -m flask run --host=0.0.0.0
``` ```
3. In the cloned repository's directory, run `docker build` to build the image. 3. In the cloned repository's directory, run `docker build` to build the image.
```console ```console
$ docker build -t python-docker-dev . $ docker build -t python-docker-dev .
``` ```
@ -101,9 +122,11 @@ You'll need to clone a new repository to get a sample application that includes
5. Run `docker run` with the following options to run the image as a container on the same network as the database. 5. Run `docker run` with the following options to run the image as a container on the same network as the database.
{{< tabs >}}
{{< tab name="Mac / Linux" >}}
```console ```console
$ docker run \ $ docker run --rm -d \
--rm -d \
--network postgresnet \ --network postgresnet \
--name rest-server \ --name rest-server \
-p 8000:5000 \ -p 8000:5000 \
@ -111,6 +134,21 @@ You'll need to clone a new repository to get a sample application that includes
python-docker-dev python-docker-dev
``` ```
{{< /tab >}}
{{< tab name="Windows" >}}
```powershell
$ docker run --rm -d `
--network postgresnet `
--name rest-server `
-p 8000:5000 `
-e POSTGRES_PASSWORD=mysecretpassword `
python-docker-dev
```
{{< /tab >}}
{{< /tabs >}}
6. Test that your application is connected to the database and is able to list the widgets. 6. Test that your application is connected to the database and is able to list the widgets.
```console ```console