Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homework 08. Docker. Docker compose #2905

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ROOT_PASS=12345678
DB_NAME=wordpress
DB_USER=wordpress_user
DB_PASS=123456
DB_TABLE_PREFIX=wp_
DB_HOST=db
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
services:
db:
image: mariadb:latest
container_name: db
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: ${ROOT_PASS}
MYSQL_DATABASE: ${DB_NAME}
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASS}
env_file:
- .env
networks:
- database
wordpress:
depends_on:
- db
links:
- "db"
- "db:mariadb"
image: wordpress:latest
container_name: wordpress
ports:
- "8000:80"
volumes:
- wp-content:/var/www/html/wp-content
environment:
WORDPRESS_DB_NAME: ${DB_NAME}
WORDPRESS_TABLE_PREFIX: ${DB_TABLE_PREFIX}
WORDPRESS_DB_HOST: ${DB_HOST}
WORDPRESS_DB_USER: ${DB_USER}
WORDPRESS_DB_PASSWORD: ${DB_PASS}
env_file:
- .env
restart: always
networks:
- database
- wordpress
volumes:
db_data:
wp-content:
networks:
database:
driver: bridge
wordpress:
driver: bridge
driver_opts:
com.docker.network.bridge.host_binding_ipv4: "127.0.0.1"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions Yuliya_Buyalskaya/08.Docker.Docker-compose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
## Homework Assignment 1: Docker Compose for Application Stacks

There was used wordpress+mariadb of the latest versions.

[Docker-compose file](../08.Docker.Docker-compose/Homework.Assignment1/docker-compose.yaml) \
[File](../08.Docker.Docker-compose/Homework.Assignment1/.env) with environment variables

Run docker compose

```shell
user@vm5:~/sa.it-academy.by/Yuliya_Buyalskaya/08.Docker.Docker-compose/Homework.Assignment1$ sudo docker compose up -d
[+] Running 32/2
✔ db Pulled 220.3s
✔ wordpress Pulled 216.9s
[+] Running 6/6
✔ Network homeworkassignment1_wordpress Created 1.5s
✔ Network homeworkassignment1_database Created 1.6s
✔ Volume "homeworkassignment1_db_data" Created 0.0s
✔ Volume "homeworkassignment1_wp-content" Created 0.0s
✔ Container db Started 5.3s
✔ Container wordpress Started 9.5s
✔ Container wordpress Started
```

Check that wordpress is running. Because docker container is running on Ubuntu virtual mashine to access wordpress from the Windows is used IP address of Virtual machine.

![start page of wordpress](../08.Docker.Docker-compose/Homework.Assignment1/pictures/1.jpg)
![move to the next page](../08.Docker.Docker-compose/Homework.Assignment1/pictures/2.jpg)
![move to the login page](../08.Docker.Docker-compose/Homework.Assignment1/pictures/3.jpg)
![login by wordpress-user](../08.Docker.Docker-compose/Homework.Assignment1/pictures/4.jpg)


## Homework Assignment 2: Docker build automation (github action)

Use simple [spring-boot app](https://github.com/Julie717/simple-app) that was created in previous homework 07.Docker. \
[Dockerfile](https://github.com/Julie717/simple-app/blob/master/Dockerfile)

Build image

```shell
user@vm5:~/simple-app$ sudo docker build -t simple-app .
[+] Building 949.2s (13/13) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 343B 0.0s
=> [internal] load metadata for docker.io/library/openjdk:17 2.5s
=> [internal] load metadata for docker.io/library/gradle:8.12-jdk-alpine 2.5s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> [temp 1/4] FROM docker.io/library/gradle:8.12-jdk-alpine@sha256:8160c 0.0s
=> [stage-1 1/3] FROM docker.io/library/openjdk:17@sha256:528707081fdb95 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 40.72kB 0.1s
=> CACHED [temp 2/4] WORKDIR /home/user/app/ 0.0s
=> [temp 3/4] COPY . . 0.3s
=> [temp 4/4] RUN gradle build 944.5s
=> CACHED [stage-1 2/3] WORKDIR /home/user/app/ 0.0s
=> [stage-1 3/3] COPY --from=temp /home/user/app/ . 0.3s
=> exporting to image 0.5s
=> => exporting layers 0.4s
=> => writing image sha256:1e93faba83e58f32c857b9ec4f3d4b55b026aa1d495d2 0.0s
=> => naming to docker.io/library/simple-app 0.0s
```
Check that image was built

```shell
user@vm5:~/simple-app$ sudo docker images | grep simple-app
simple-app latest 1e93faba83e5 4 minutes ago 493MB
```

Run container from image

```shell
user@vm5:~/simple-app$ sudo docker run -d -p 8080:8080 --name simple-app simple-app
c5a1dcd59fd627d8cce622a00ad5685cb25f5655c8dcc8414740253bb9a75e85
```

Check from Windows using virtual machine address

![spring-boot app run](../08.Docker.Docker-compose/Homework.Assignment2/pictures/1.jpg)

Add [Github workflow](https://github.com/Julie717/simple-app/blob/master/.github/workflows/push-image.yaml) for pushing image
to docker hub and github container register.

Secrets were added there

![secrets](../08.Docker.Docker-compose/Homework.Assignment2/pictures/2.jpg)

Check that image appears in docker hub and github container register

![docker hub](../08.Docker.Docker-compose/Homework.Assignment2/pictures/3.jpg)
![github container register](../08.Docker.Docker-compose/Homework.Assignment2/pictures/4.jpg)

Check that slack notification works

![slack notification](../08.Docker.Docker-compose/Homework.Assignment2/pictures/5.jpg)
2 changes: 1 addition & 1 deletion Yuliya_Buyalskaya/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
[Homework 05. Ansible start](../Yuliya_Buyalskaya/05.Ansible.start/README.md) \
[Homework 06. Ansible Workshop](../Yuliya_Buyalskaya/06.Ansible.Workshop/README.md) \
[Homework 07. Docker](../Yuliya_Buyalskaya/07.Docker/README.md)

[08. Docker. Docker compose](../Yuliya_Buyalskaya/08.Docker.Docker-compose/README.md)
Loading