Skip to content

Commit

Permalink
Review Docker Compose (#11)
Browse files Browse the repository at this point in the history
Co-authored-by: Gioacchino Vino <[email protected]>
  • Loading branch information
jvino and Gioacchino Vino authored Sep 11, 2024
1 parent 19ecd5b commit d74bfa1
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 15 deletions.
7 changes: 6 additions & 1 deletion docs/compose/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,16 @@ The default value should be placed after the `:-` characters.

Since more approaches are supported, Docker compose uses the following priority order, overwriting the less important with the higher ones:

When multiple approches are used, Docker compose prioritizes configuration as follows, with high-priorit values overriding lower-priority ones:
When multiple approaches are used, Docker compose prioritizes configuration as follows, with high-priority values overriding lower-priority ones:

1. Compose file (highest important)

2. Shell environment variables

3. Environment file

4. Dockerfile

5. Undefined variables (lowest important)

#### Health checks
Expand Down
103 changes: 89 additions & 14 deletions docs/compose/hands-on.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

### Hands-on 1

Write the docker-compose.yml file for the following Docker CLI inserting the `depends_on` condition on db health check
Write the compose.yaml file for the following Docker CLI inserting the `depends_on` condition on db health check

=== "Exercise details"
```bash
Expand All @@ -14,7 +14,7 @@ Write the docker-compose.yml file for the following Docker CLI inserting the `de
-e MYSQL_ROOT_PASSWORD=somewordpress \
-e MYSQL_USER=wordpress_user \
-e MYSQL_PASSWORD=wordpress_password \
-e MYSQL_DATABASE=wordpress_db \
-e MYSQL_DATABASE=wordpress_database \
--restart always \
--health-cmd="mysqladmin ping --silent" \
--health-interval=10s \
Expand Down Expand Up @@ -43,31 +43,31 @@ Write the docker-compose.yml file for the following Docker CLI inserting the `de
image: mariadb:10.6.4-focal
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=somewordpress
- MYSQL_DATABASE=wordpress_database
- MYSQL_USER=wordpress_user
- MYSQL_PASSWORD=wordpress_password
- MYSQL_DATABASE=wordpress_database
restart: always
healthcheck:
test: ["CMD", "mysqladmin", "ping", "--silent"]
test: "mysqladmin ping --silent"
interval: 10s
start_period: 10s
timeout: 10s
retries: 60
start_period: 10s

wordpress:

wp:
image: wordpress:latest
volumes:
- wp_data:/var/www/html
ports:
- 8081:80
restart: always
- 8080:80
environment:
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=wordpress_user
- WORDPRESS_DB_PASSWORD=wordpress_password
- WORDPRESS_DB_NAME=wordpress_database
restart: always
depends_on:
db:
condition: service_healthy
Expand All @@ -79,7 +79,7 @@ Write the docker-compose.yml file for the following Docker CLI inserting the `de

### Hands-on 2

Write the docker-compose.yml file that builds the following Dockerfile and uses it
Write the compose.yaml file that builds the following Dockerfile and uses it

=== "Exercise details"
```
Expand All @@ -92,10 +92,23 @@ Write the docker-compose.yml file that builds the following Dockerfile and uses
--NotebookApp.token='' \
--NotebookApp.password=''
```
=== "Solution"
Jupyter notebook to test the configuration

```python
import pandas as pd
output_path = 'my_output.csv'

data = {
'apples': [3, 2, 0, 1],
'oranges': [0, 3, 7, 2]
}
df = pd.DataFrame(data)

df.to_csv(output_path)
```

=== "Solution 1"
```bash
mkdir exercise2
cd exercise2
cat > requirements.txt << EOF
pandas
numpy
Expand All @@ -116,6 +129,68 @@ Write the docker-compose.yml file that builds the following Dockerfile and uses
command: /opt/conda/bin/python3.11 /opt/conda/bin/jupyter-lab --no-browser --allow-root --NotebookApp.token='' --NotebookApp.password=''
EOF

# To execute the application run:
# docker compose up
```
=== "Solution 2"
```bash
cat > requirements.txt << EOF
pandas
numpy
EOF

cat > Dockerfile << EOF
FROM jupyter/minimal-notebook
COPY requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
EOF

cat > compose.yaml << EOF
services:
my_jupyter:
build: .
ports:
- 8888:8888
command: "/opt/conda/bin/python3.11 \
/opt/conda/bin/jupyter-lab \
--no-browser \
--allow-root \
--NotebookApp.token='' \
--NotebookApp.password='' "
EOF

# To execute the application run:
# docker compose up
```

=== "Solution 3"
```bash
cat > requirements.txt << EOF
pandas
numpy
EOF

cat > Dockerfile << EOF
FROM jupyter/minimal-notebook
COPY requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
EOF

cat > compose.yaml << EOF
services:
my_jupyter:
build: .
ports:
- 8888:8888
command:
- /opt/conda/bin/python3.11
- /opt/conda/bin/jupyter-lab
- --no-browser
- --allow-root
- --NotebookApp.token=''
- --NotebookApp.password=''
EOF

# To execute the application run:
# docker compose up
```

0 comments on commit d74bfa1

Please sign in to comment.