├── .gitignore ├── LICENSE ├── Part3-Docker-Run ├── Lesson3.1-Running-Container-Step-By-Step │ └── console_cmds_flow.sh ├── Lesson3.2-Multiple-Docker-Containers │ └── console_cmds_flow.sh ├── Lesson3.3-Shared-Volume-Mounting │ ├── console_cmds_flow.sh │ ├── myfile.txt │ └── myrar.rar ├── Lesson3.4-PHP-with-volume-mounting │ ├── console_cmds_flow.sh │ └── index.php └── Lesson3.5-Server-Logs │ ├── console_cmds_flow.sh │ └── index.php ├── Part4-Dockerfile ├── Lesson4.1-First-Dockerfile │ ├── Dockerfile │ ├── console_cmds_flow.sh │ └── index.php ├── Lesson4.2-PHP-Dev-Server-Container │ ├── Dockerfile │ ├── console_cmds_flow.sh │ └── index.php ├── Lesson4.3-Ship-your-Web-Application-using-Apache-PHP │ ├── Dockerfile │ ├── console_cmds_flow.sh │ └── index.php └── Lesson4.4-Uploading-Images-to-Docker-Hub │ ├── Dockerfile │ └── console_cmds_flow.sh ├── Part5-Docker-compose-volumes ├── Lesson1-docker-compose │ ├── Dockerfile │ ├── console_cmds_flow.sh │ ├── docker-compose.yml │ └── index.php ├── Lesson2-docker-compose-image-volume │ ├── console_cmds_flow.sh │ ├── docker-compose.yml │ └── index.php ├── Lesson3-docker-compose-and -dockerfile │ ├── Dockerfile │ ├── console_cmds_flow.sh │ ├── docker-compose.yml │ └── index.php ├── Lesson4-Build-your-environment-with-a-simple-php-apache-and-database-using-docker-compose │ ├── Dockerfile │ ├── docker-compose.yml │ └── index.php ├── Lesson5-Databases-and-Data-Peristence-in-Host-Directory-Mounted-Volumes │ ├── Dockerfile │ ├── docker-compose.yml │ └── index.php └── Lesson6-Data-Peristence-in-Named-Volumes-and-Data-Sharing-Across-Containers │ └── docker-compose.yml ├── Part6-Networks ├── Lesson6.1-Understanding-Network-Segregation-in-Docker │ └── console_cmds_flow.sh ├── Lesson6.2-Network-in-the-docker-compose-yml │ └── docker-compose.yml └── Lesson6.3-Using-networks-in-docker-compose-for-Segregation │ ├── docker-compose.yml │ └── nginx.conf ├── Part7-Real-Examples └── Lesson7.1-Real-World-Docker-Compose-File │ └── docker-compose.yml ├── README.md ├── certificate.jpg ├── composer.json └── docker-logo.png /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Maxim Gavrilenko 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Part3-Docker-Run/Lesson3.1-Running-Container-Step-By-Step/console_cmds_flow.sh: -------------------------------------------------------------------------------- 1 | # run docker-container from image ubuntu 2 | docker run -it ubuntu /bin/bash 3 | 4 | # start docker-container when it stops 5 | docker start container_name 6 | 7 | # attach docker-container (like exec + bash) 8 | docker attach container_name 9 | 10 | # stop docker-container 11 | docker stop container_name 12 | 13 | # remove docker-container 14 | docker rm container_name -------------------------------------------------------------------------------- /Part3-Docker-Run/Lesson3.2-Multiple-Docker-Containers/console_cmds_flow.sh: -------------------------------------------------------------------------------- 1 | # run docker-container from image ubuntu 2 | # with name linux1, detached and remove when it stops 3 | docker run -it -d --rm --name linux1 ubuntu /bin/bash 4 | 5 | # run other docker-container from image ubuntu 6 | # with name linux2, detached and remove when it stops 7 | docker run -it -d --rm --name linux2 ubuntu /bin/bash 8 | 9 | #try to create files in each container. And they will be isolated 10 | 11 | docker stop linux1 linux2 12 | 13 | docker rm linux1 linux2 -------------------------------------------------------------------------------- /Part3-Docker-Run/Lesson3.3-Shared-Volume-Mounting/console_cmds_flow.sh: -------------------------------------------------------------------------------- 1 | # run docker-container from image ubuntu with shared directory with host machine 2 | docker run --rm -v ${PWD}:/myvol ubuntu /bin/bash -c "ls -lha > /myvol/myfile.txt" 3 | 4 | # unpackage some archive throught container and remove it 5 | # https://hub.docker.com/r/klutchell/rar 6 | # flag -w for working directory (like cd) 7 | docker run --rm -v ${PWD}:/files -w /files klutchell/rar a /files/myrar.rar /files/myfile.txt -------------------------------------------------------------------------------- /Part3-Docker-Run/Lesson3.3-Shared-Volume-Mounting/myfile.txt: -------------------------------------------------------------------------------- 1 | total 76K 2 | drwxr-xr-x 1 root root 4.0K Feb 3 08:04 . 3 | drwxr-xr-x 1 root root 4.0K Feb 3 08:04 .. 4 | -rwxr-xr-x 1 root root 0 Feb 3 08:04 .dockerenv 5 | drwxr-xr-x 2 root root 4.0K Dec 2 12:43 bin 6 | drwxr-xr-x 2 root root 4.0K Apr 24 2018 boot 7 | drwxr-xr-x 5 root root 340 Feb 3 08:04 dev 8 | drwxr-xr-x 1 root root 4.0K Feb 3 08:04 etc 9 | drwxr-xr-x 2 root root 4.0K Apr 24 2018 home 10 | drwxr-xr-x 8 root root 4.0K May 23 2017 lib 11 | drwxr-xr-x 2 root root 4.0K Dec 2 12:43 lib64 12 | drwxr-xr-x 2 root root 4.0K Dec 2 12:43 media 13 | drwxr-xr-x 2 root root 4.0K Dec 2 12:43 mnt 14 | drwxrwxr-x 2 1000 1000 4.0K Feb 3 08:04 myvol 15 | drwxr-xr-x 2 root root 4.0K Dec 2 12:43 opt 16 | dr-xr-xr-x 447 root root 0 Feb 3 08:04 proc 17 | drwx------ 2 root root 4.0K Dec 2 12:43 root 18 | drwxr-xr-x 1 root root 4.0K Dec 19 04:21 run 19 | drwxr-xr-x 1 root root 4.0K Dec 19 04:21 sbin 20 | drwxr-xr-x 2 root root 4.0K Dec 2 12:43 srv 21 | dr-xr-xr-x 13 root root 0 Feb 3 08:04 sys 22 | drwxrwxrwt 2 root root 4.0K Dec 2 12:43 tmp 23 | drwxr-xr-x 1 root root 4.0K Dec 2 12:43 usr 24 | drwxr-xr-x 1 root root 4.0K Dec 2 12:43 var 25 | -------------------------------------------------------------------------------- /Part3-Docker-Run/Lesson3.3-Shared-Volume-Mounting/myrar.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maxlen/docker-howto/a5158d0b8f32fb2e4562af286037935735dae659/Part3-Docker-Run/Lesson3.3-Shared-Volume-Mounting/myrar.rar -------------------------------------------------------------------------------- /Part3-Docker-Run/Lesson3.4-PHP-with-volume-mounting/console_cmds_flow.sh: -------------------------------------------------------------------------------- 1 | # PHP-with-volume-mounting 2 | # create container from php-image 3 | docker run -it --rm -v ${PWD}:/my-files -w /my-files --name php-script php:7.4-cli /bin/bash 4 | 5 | # create php-file from console of container: 6 | echo ' index.php 7 | 8 | # exit from container and try to run: 9 | docker run -it --rm -v ${PWD}:/my-files -w /my-files --name php-script php:7.4-cli php index.php -------------------------------------------------------------------------------- /Part3-Docker-Run/Lesson3.4-PHP-with-volume-mounting/index.php: -------------------------------------------------------------------------------- 1 | hello world"; 2 | -------------------------------------------------------------------------------- /Part4-Dockerfile/Lesson4.4-Uploading-Images-to-Docker-Hub/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | 3 | RUN apk update && apk add curl; 4 | 5 | ENTRYPOINT ["curl"] -------------------------------------------------------------------------------- /Part4-Dockerfile/Lesson4.4-Uploading-Images-to-Docker-Hub/console_cmds_flow.sh: -------------------------------------------------------------------------------- 1 | # build docker image with tag 2 | docker build -t mycurl . 3 | 4 | # try to 5 | docker run mycurl google.com 6 | 7 | docker rm container_name 8 | 9 | # OR remove all stopped containers 10 | docker system prune 11 | 12 | # login to docker 13 | docker login 14 | 15 | # re-tag image 16 | docker tag mycurl maxlenash/mycurl:latest 17 | 18 | # lets see 19 | docker image ls | grep maxlenash 20 | # maxlenash/mycurl latest 5fb1508ea566 About a minute ago 8.52MB 21 | 22 | # push image to docker-hub 23 | docker push maxlenash/mycurl:latest 24 | 25 | docker rmi mycurl maxlenash/mycurl 26 | 27 | # now we can execute 28 | docker run --rm maxlenash/mycurl google.com 29 | 30 | # and remove an image 31 | docker rmi mycurl maxlenash/mycurl 32 | -------------------------------------------------------------------------------- /Part5-Docker-compose-volumes/Lesson1-docker-compose/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.4-apache 2 | 3 | COPY index.php /var/www/html 4 | -------------------------------------------------------------------------------- /Part5-Docker-compose-volumes/Lesson1-docker-compose/console_cmds_flow.sh: -------------------------------------------------------------------------------- 1 | # start containers 2 | docker-compose up 3 | 4 | # build/rebuild container 5 | docker-compo up --build 6 | 7 | # stop and remove containers and networks 8 | docker-compose down 9 | -------------------------------------------------------------------------------- /Part5-Docker-compose-volumes/Lesson1-docker-compose/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | php: 5 | ports: 6 | - "8080:80" 7 | build: 8 | context: ./ 9 | dockerfile: Dockerfile 10 | -------------------------------------------------------------------------------- /Part5-Docker-compose-volumes/Lesson1-docker-compose/index.php: -------------------------------------------------------------------------------- 1 | connect_errno > 0) { 11 | echo $conn->connect_error; 12 | } else { 13 | echo "DB Connection successful\n\n"; 14 | 15 | $result = mysqli_query($conn, "SHOW DATABASES;"); 16 | while ($row = mysqli_fetch_row($result)) { 17 | echo $row[0] . "\n\n"; 18 | } 19 | } -------------------------------------------------------------------------------- /Part5-Docker-compose-volumes/Lesson5-Databases-and-Data-Peristence-in-Host-Directory-Mounted-Volumes/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.4-apache 2 | 3 | RUN apt-get -y update \ 4 | && apt-get install -y libicu-dev \ 5 | && docker-php-ext-configure intl \ 6 | && docker-php-ext-install intl 7 | 8 | RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli 9 | -------------------------------------------------------------------------------- /Part5-Docker-compose-volumes/Lesson5-Databases-and-Data-Peristence-in-Host-Directory-Mounted-Volumes/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | php: 5 | image: phpapp:123 6 | build: 7 | context: ./ 8 | dockerfile: Dockerfile 9 | ports: 10 | - "8080:80" 11 | volumes: 12 | - "./:/var/www/html" 13 | container_name: my-php-app 14 | 15 | db: 16 | image: mysql:8.0 17 | restart: always 18 | environment: 19 | MYSQL_ROOT_PASSWORD: mypassword 20 | container_name: my-db 21 | volumes: 22 | - "./dbData:/var/lib/mysql" 23 | -------------------------------------------------------------------------------- /Part5-Docker-compose-volumes/Lesson5-Databases-and-Data-Peristence-in-Host-Directory-Mounted-Volumes/index.php: -------------------------------------------------------------------------------- 1 | connect_errno > 0) { 11 | echo $conn->connect_error; 12 | } else { 13 | echo "DB Connection successful\n\n"; 14 | 15 | $result = mysqli_query($conn, "SHOW DATABASES;"); 16 | while ($row = mysqli_fetch_row($result)) { 17 | echo $row[0] . "\n\n"; 18 | } 19 | } -------------------------------------------------------------------------------- /Part5-Docker-compose-volumes/Lesson6-Data-Peristence-in-Named-Volumes-and-Data-Sharing-Across-Containers/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | php: 5 | image: phpapp:123 6 | build: 7 | context: ./ 8 | dockerfile: Dockerfile 9 | ports: 10 | - "8080:80" 11 | volumes: 12 | - "./:/var/www/html" 13 | container_name: my-php-app 14 | 15 | db: 16 | image: mysql:8.0 17 | restart: always 18 | environment: 19 | MYSQL_ROOT_PASSWORD: mypassword 20 | container_name: my-db 21 | volumes: 22 | - "./dbData:/var/lib/mysql" 23 | 24 | volumes: 25 | my-vol: 26 | - name: my-vol -------------------------------------------------------------------------------- /Part6-Networks/Lesson6.1-Understanding-Network-Segregation-in-Docker/console_cmds_flow.sh: -------------------------------------------------------------------------------- 1 | # show list of all networks 2 | docker network ls 3 | 4 | # remove all networks not used by at least one container (now) 5 | docker network prune 6 | 7 | # run httpd-container 8 | docker run --rm --name my-webserver -d httpd 9 | 10 | # get info about network/s used by container with name my-webserver 11 | docker inspect my-webserver 12 | 13 | # open browser and get ip-adress from info (from docker inspect ...) and we can se nothing. 14 | # Cause we weren't expose+map port 15 | 16 | # tets try to get this page from other container (by curl) 17 | docker run --rm tom1808/mycurl my-webserver 18 | # it woudn't work 19 | 20 | # tets try to do it by ip 21 | docker run --rm tom1808/mycurl 172.17.0.1 22 | # it works 23 | 24 | # lets create simple-network 25 | docker network create simple-network 26 | 27 | # and run httpd-container again but with this network 28 | docker run --rm -d --name my-webserver --network simple-network httpd 29 | 30 | # and now run curl-container with this network too 31 | docker run --rm tom1808/mycurl --network simple-network my-webserver 32 | # it works! curl-container can get http-container throught simple-network 33 | 34 | # ok. So lets stop container and remove network 35 | docker stop my-webserver 36 | docker network rm simple-network 37 | 38 | -------------------------------------------------------------------------------- /Part6-Networks/Lesson6.2-Network-in-the-docker-compose-yml/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | app-httpd: 5 | image: httpd:latest 6 | container_name: app-httpd 7 | ports: 8 | - "8089:80" 9 | networks: 10 | - app-network 11 | 12 | networks: 13 | app-network: 14 | -------------------------------------------------------------------------------- /Part6-Networks/Lesson6.3-Using-networks-in-docker-compose-for-Segregation/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | web: 5 | image: nginx:alpine 6 | container_name: udemy-web 7 | volumes: 8 | - ./nginx.conf:/etc/nginx/nginx.conf 9 | ports: 10 | - 8090:80 11 | networks: 12 | - app1_net 13 | - app2_net 14 | 15 | app1: 16 | image: httpd:latest 17 | container_name: udemy-app1 18 | networks: 19 | - app1_net 20 | 21 | app2: 22 | image: httpd:latest 23 | container_name: udemy-app2 24 | networks: 25 | - app2_net 26 | 27 | networks: 28 | app1_net: 29 | app2_net: 30 | -------------------------------------------------------------------------------- /Part6-Networks/Lesson6.3-Using-networks-in-docker-compose-for-Segregation/nginx.conf: -------------------------------------------------------------------------------- 1 | events {} 2 | http { 3 | server { 4 | listen 80; 5 | listen [::]:80; 6 | 7 | server_name example.com; 8 | 9 | location / { 10 | proxy_pass http://app1:80/; 11 | } 12 | 13 | location /app2 { 14 | proxy_pass http://app2:80/; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Part7-Real-Examples/Lesson7.1-Real-World-Docker-Compose-File/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.1' 2 | 3 | services: 4 | 5 | wordpress: 6 | image: wordpress 7 | restart: always 8 | ports: 9 | - 8080:80 10 | environment: 11 | WORDPRESS_DB_HOST: db 12 | WORDPRESS_DB_USER: exampleuser 13 | WORDPRESS_DB_PASSWORD: examplepass 14 | WORDPRESS_DB_NAME: exampledb 15 | volumes: 16 | - app:/var/www/html 17 | 18 | db: 19 | image: mysql:5.7 20 | restart: always 21 | environment: 22 | MYSQL_DATABASE: exampledb 23 | MYSQL_USER: exampleuser 24 | MYSQL_PASSWORD: examplepass 25 | MYSQL_RANDOM_ROOT_PASSWORD: '1' 26 | volumes: 27 | - db:/var/lib/mysql 28 | 29 | volumes: 30 | app: 31 | db: 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HowTo Docker 2 | 3 | Docker, Dockerfile, and Docker-Compose (2020 ready!) 4 | 5 | Learn Docker, Containers vs. Images, Dockerfile, Docker-Compose 6 | 7 | With Practical Hands-On Exercises! 8 | 9 | ![Scheme](./docker-logo.png) 10 | 11 | ### based on video-course 12 | https://www.udemy.com/course/docker-and-docker-compose-hands-on-by-example/ 13 | 14 | Thomas Wiesner. Teaching over 60,000 Students about Development (https://www.facebook.com/tomscourses/) 15 | 16 | ### What you will learn 17 | - You will learn to use Docker with Hands-On Demos and Exercises 18 | - Know the most important Docker-Run Flags and Everyday Use-Cases 19 | - Be able to read, understand and write your own Dockerfiles 20 | - Read and write your own docker-compose yaml files 21 | - Understand the difference between Host-Volume and Named-Volume mounting 22 | - Improve real-world docker-compose yaml files\ 23 | 24 | ### Steps: 25 | - Part 1 and 2: Introduction and install docker to desktop 26 | - Part 3: Docker run and docker commands 27 | - Part 4: Dockerfile and docker commands 28 | - Part 5: Docker-compose. Volumes and docker-compose + dockerfile 29 | - Part 6: Networks and docker, docker-compose 30 | - Part 7: Examples 31 | 32 | ### Helpful documentation 33 | #### Docker: 34 | https://docs.docker.com/ 35 | 36 | For example "MariaDB doc and env-variable": https://hub.docker.com/_/mariadb 37 | #### docker-compose: 38 | https://docs.docker.com/compose/ 39 | 40 | For example "Quickstart: Compose and WordPress": https://docs.docker.com/compose/wordpress/ 41 | 42 | or in DocherHub: https://hub.docker.com/_/wordpress 43 | 44 | ### useful documentation: 45 | dockerfile best practices: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/ 46 | 47 | 48 | 49 | # Fast HowTo (Docker, Dockerfile, docker-compose) 50 | 51 | ## Main commands and features 52 | 53 | #### general commands with Docker 54 | ```dotenv 55 | # show all containers 56 | docker ps -a 57 | 58 | # build image with tag (with Dockerfile) 59 | docker build -t myphpapp . 60 | 61 | # run docker-container from image ubuntu 62 | docker run -it ubuntu /bin/bash 63 | 64 | # start docker-container when it stops 65 | docker start container_name 66 | 67 | # attach docker-container (like exec + bash) 68 | docker attach container_name 69 | 70 | # stop docker-container 71 | docker stop container_name 72 | 73 | # remove docker-container 74 | docker rm container_name 75 | 76 | # remove image 77 | docker rmi image_name_or_tag 78 | 79 | # Run container from image 'ubuntu' in interactive mode (-it) 80 | # with attached volume 'my-vol' (-v) 81 | # with name linux1, detached 82 | # and remove the container when it will stop (--rm) 83 | docker run -v my-vol:/my-data --rm -it -d --name linux1 ubuntu /bin/bash 84 | 85 | # run docker-container from image ubuntu with shared directory with host machine 86 | docker run --rm -v ${PWD}:/myvol ubuntu /bin/bash -c "ls -lha > /myvol/myfile.txt" 87 | 88 | # create container from image with port mapping and volume mointing 89 | docker run -d --rm -p 8080:80 -v ${PWD}:/var/www/html php:7.4-apache 90 | 91 | ``` 92 | 93 | #### volumes 94 | ```dotenv 95 | # create volume with name 'my-vol' 96 | docker volume create --name my-vol 97 | 98 | # show all volumes 99 | docker volume ls 100 | 101 | # remove volume with name 'my-vol' 102 | docker volume rm my-vol 103 | ``` 104 | #### networks 105 | ```dotenv 106 | # create network and start container which use this network 107 | docker network create simple-network 108 | docker run --rm -d --name my-webserver --network simple-network httpd 109 | 110 | # run docker container with port mapping 111 | docker run -p 8080:8000 myphpapp:web 112 | 113 | # run container with port mapping and name 114 | docker run --name myphp-apache -p 8080:80 myphpapp:apache 115 | 116 | # show all networks 117 | docker network ls 118 | 119 | # remove volume with name 'my-vol' 120 | docker network rm my-network 121 | 122 | # remove all networks not used by at least one container (now) 123 | docker network prune 124 | ``` 125 | #### docker-compose commands 126 | ```dotenv 127 | # start container/s and detach 128 | docker-compose up -d 129 | 130 | # build/rebuild container 131 | docker-compose up --build 132 | 133 | # list of started containers 134 | docker-compose ps 135 | 136 | # stop and remove containers and networks 137 | docker-compose down 138 | 139 | # build images without cache 140 | docker-compose build --no-cache service1 service2 141 | 142 | ``` 143 | 144 | #### Dockerfile 145 | ```dotenv 146 | # set image from dockerhub 147 | FROM php:7.4-apache 148 | 149 | RUN apt-get -y update \ 150 | && apt-get install -y libicu-dev \ 151 | && docker-php-ext-configure intl \ 152 | && docker-php-ext-install intl 153 | 154 | RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli 155 | 156 | # set file|catalog wich we use in web-server 157 | COPY index.php /var/www/html 158 | 159 | # use port 160 | EXPOSE 8000 161 | 162 | # after container start 163 | CMD ["php", "-S", "0.0.0.0:8000"] 164 | 165 | ``` 166 | 167 | #### docker-compose.yml 168 | ```dotenv 169 | version: '3.7' 170 | 171 | services: 172 | web: 173 | image: nginx:alpine 174 | container_name: udemy-web 175 | volumes: 176 | - ./nginx.conf:/etc/nginx/nginx.conf 177 | ports: 178 | - 8090:80 179 | networks: 180 | - app1_net 181 | - app2_net 182 | 183 | app1: 184 | image: httpd:latest 185 | container_name: udemy-app1 186 | networks: 187 | - app1_net 188 | 189 | app2: 190 | image: httpd:latest 191 | container_name: udemy-app2 192 | networks: 193 | - app2_net 194 | 195 | networks: 196 | app1_net: 197 | app2_net: 198 | ``` 199 | 200 | #### Examples 201 | ```dotenv 202 | # EXAMPLE 1: (Lesson3.3-Shared-Volume-Mounting) 203 | 204 | # unpackage some archive throught container and remove it 205 | # https://hub.docker.com/r/klutchell/rar 206 | # flag -w for working directory (like cd) 207 | docker run --rm -v ${PWD}:/files -w /files klutchell/rar a /files/myrar.rar /files/myfile.txt 208 | 209 | # EXAMPLE 2: (Part3-Docker-Run/Lesson3.4-PHP-with-volume-mounting) 210 | 211 | # PHP-with-volume-mounting 212 | # create container from php-image 213 | docker run -it --rm -v ${PWD}:/my-files -w /my-files --name php-script php:7.4-cli /bin/bash 214 | 215 | # create php-file from console of container: 216 | echo ' index.php 217 | 218 | # exit from container and try to run: 219 | docker run -it --rm -v ${PWD}:/my-files -w /my-files --name php-script php:7.4-cli php index.php 220 | 221 | # EXAMPLE 3: 222 | 223 | 224 | ``` 225 | 226 | #### Push image to docker-hub 227 | 1. register or login in https://hub.docker.com/ 228 | 2. login to docker-hub in your pc [bash]: 229 | ```dotenv 230 | docker login 231 | ``` 232 | 3. create Dockerfile: 233 | ```dotenv 234 | FROM alpine 235 | 236 | RUN apk update && apk add curl; 237 | 238 | ENTRYPOINT ["curl"] 239 | ``` 240 | 4. in bash: 241 | ```dotenv 242 | docker run mycurl google.com 243 | ``` 244 | 5. re-tag image: 245 | ```dotenv 246 | docker tag mycurl maxlenash/mycurl:latest 247 | ``` 248 | 6. push image to docker-hub: 249 | ```dotenv 250 | docker push maxlenash/mycurl:latest 251 | ``` 252 | 7. that's all. Now we can execute: 253 | ```dotenv 254 | docker run --rm maxlenash/mycurl google.com 255 | ``` 256 | 8. remove unnecessary: 257 | ```dotenv 258 | docker rmi mycurl maxlenash/mycurl 259 | ``` 260 | 261 | 262 | #### Done 263 | 264 | At the end of course you'll have certificate like that: 265 | 266 | ![Scheme](./certificate.jpg) 267 | 268 | ##### whoami 269 | That git-repository created by Maxim Gavrilenko https://www.linkedin.com/in/maxim-gavrilenko 270 | -------------------------------------------------------------------------------- /certificate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maxlen/docker-howto/a5158d0b8f32fb2e4562af286037935735dae659/certificate.jpg -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "maxlen/udemy-docker-howto", 3 | "type": "project", 4 | "description": "Docker, Dockerfile, and Docker-Compose (2020 ready!) Learn Docker, Containers vs. Images, Dockerfile, Docker-Compose -- With Practical Hands-On Exercises.", 5 | "keywords": [ 6 | "docker", 7 | "docker-compose", 8 | "udemy", 9 | "learn docker", 10 | "free course" 11 | "maxlen", 12 | "ml" 13 | ], 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /docker-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maxlen/docker-howto/a5158d0b8f32fb2e4562af286037935735dae659/docker-logo.png --------------------------------------------------------------------------------