forked from maricaantonacci/docker-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add compose section * Add "#include <stdio.h>" to hello.c example (#5) * Update intro and container sections (#6) * Fix automation section (#8) * Add Github action section * Update automation section * Add Docker compose section (#7) * Add Compose content * Add Compose content * Add Compose content * Add compose section * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content * Add Compose content --------- Co-authored-by: Gioacchino Vino <[email protected]> --------- Co-authored-by: Lisa <[email protected]> Co-authored-by: jvino <[email protected]> Co-authored-by: Gioacchino Vino <[email protected]>
- Loading branch information
1 parent
a9a9403
commit 19ecd5b
Showing
14 changed files
with
1,127 additions
and
323 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
|
||
### Hands-on 1 | ||
|
||
Write the docker-compose.yml file for the following Docker CLI inserting the `depends_on` condition on db health check | ||
|
||
=== "Exercise details" | ||
```bash | ||
docker network create wordpress_net | ||
docker volume create db_data | ||
docker volume create wp_data | ||
docker container run --name db \ | ||
--network wordpress_net \ | ||
-v db_data:/var/lib/mysql \ | ||
-e MYSQL_ROOT_PASSWORD=somewordpress \ | ||
-e MYSQL_USER=wordpress_user \ | ||
-e MYSQL_PASSWORD=wordpress_password \ | ||
-e MYSQL_DATABASE=wordpress_db \ | ||
--restart always \ | ||
--health-cmd="mysqladmin ping --silent" \ | ||
--health-interval=10s \ | ||
--health-start-period=10s \ | ||
--health-timeout=10s \ | ||
--health-retries=60 \ | ||
--restart always \ | ||
-d \ | ||
mariadb:10.6.4-focal | ||
|
||
docker run --name wp \ | ||
--network wordpress_net \ | ||
-v wp_data:/var/www/html \ | ||
-p 8080:80 \ | ||
-e WORDPRESS_DB_HOST=db \ | ||
-e WORDPRESS_DB_USER=wordpress_user \ | ||
-e WORDPRESS_DB_PASSWORD=wordpress_password \ | ||
-e WORDPRESS_DB_NAME=wordpress_database \ | ||
-d \ | ||
wordpress | ||
``` | ||
=== "Solution" | ||
```yaml | ||
services: | ||
db: | ||
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 | ||
healthcheck: | ||
test: ["CMD", "mysqladmin", "ping", "--silent"] | ||
interval: 10s | ||
timeout: 10s | ||
retries: 60 | ||
start_period: 10s | ||
|
||
wordpress: | ||
image: wordpress:latest | ||
volumes: | ||
- wp_data:/var/www/html | ||
ports: | ||
- 8081:80 | ||
restart: always | ||
environment: | ||
- WORDPRESS_DB_HOST=db | ||
- WORDPRESS_DB_USER=wordpress_user | ||
- WORDPRESS_DB_PASSWORD=wordpress_password | ||
- WORDPRESS_DB_NAME=wordpress_database | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
|
||
volumes: | ||
db_data: | ||
wp_data: | ||
``` | ||
|
||
### Hands-on 2 | ||
|
||
Write the docker-compose.yml file that builds the following Dockerfile and uses it | ||
|
||
=== "Exercise details" | ||
``` | ||
base-image: jupyter/minimal-notebook | ||
python module to install: pandas, numpy | ||
expose port: 8888 | ||
command: /opt/conda/bin/python3.11 /opt/conda/bin/jupyter-lab \ | ||
--no-browser \ | ||
--allow-root \ | ||
--NotebookApp.token='' \ | ||
--NotebookApp.password='' | ||
``` | ||
=== "Solution" | ||
```bash | ||
mkdir exercise2 | ||
cd exercise2 | ||
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 | ||
``` |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
## Create a New Repository on GitHub | ||
|
||
1. Go to GitHub and log in to your account. | ||
2. Click the `+` icon in the top right corner and select `New repository`. | ||
3. Fill out the repository name and description, then click `Create repository`. | ||
|
||
## Add GitHub as a Remote | ||
|
||
Add your newly created GitHub repository as a remote: | ||
|
||
``` | ||
git remote add github https://github.com/username/repository-name.git | ||
``` | ||
|
||
## Create a GitHub Personal Access Token: | ||
|
||
1. Go to GitHub [Personal Access Tokens](https://github.com/settings/tokens). | ||
2. Click `Generate new token`. | ||
3. Add a note, select the `repo` scope for full control of private repositories, and any other necessary scopes. | ||
4. Click `Generate token` and copy the token. This will be used as your GitHub authentication token. | ||
|
||
## Push Your Repository to GitHub | ||
|
||
Push your repository’s branches to GitHub: | ||
|
||
``` | ||
git push github --all | ||
``` | ||
|
||
## Create a GitHub Action to Build and Push Docker Images | ||
|
||
In your GitHub repository, create the necessary directory for GitHub Actions workflows: | ||
|
||
``` | ||
mkdir -p .github/workflows | ||
``` | ||
|
||
Create a new file in the `.github/workflows` directory, e.g., `build-and-push.yml`: | ||
|
||
``` | ||
name: Build and push docker image to Docker Hub | ||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
workflow_dispatch: | ||
jobs: | ||
docker: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v4 | ||
- | ||
name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- | ||
name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- | ||
name: Docker meta | ||
id: docker_meta | ||
uses: crazy-max/ghaction-docker-meta@v2 | ||
with: | ||
images: ${{ secrets.DOCKERHUB_USERNAME }}/slat | ||
tags: | | ||
type=sha | ||
type=semver,pattern={{raw}} | ||
type=ref,event=branch | ||
- | ||
name: Build & Push image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: Dockerfile | ||
push: true | ||
tags: ${{ steps.docker_meta.outputs.tags }} | ||
labels: ${{ steps.docker_meta.outputs.labels }} | ||
``` | ||
|
||
## Add Secrets to Your GitHub Repository: | ||
|
||
- Go to your GitHub repository and navigate to `Settings`. | ||
- Select `Secrets and variables` → `Actions`. | ||
- Click `New repository secret` and add the following secrets: | ||
* `DOCKERHUB_USERNAME`: Your Docker Hub username. | ||
* `DOCKERHUB_PASSWORD`: Your Docker Hub password or access token. | ||
|
||
## Commit and Push the Workflow File | ||
|
||
Add, commit, and push the workflow file to your GitHub repository: | ||
|
||
``` | ||
git add .github/workflows/build-and-push.yml | ||
git commit -m "Add GitHub Actions workflow for Docker build and push" | ||
git push | ||
``` | ||
|
||
|
Oops, something went wrong.