{"id":19959740,"url":"https://github.com/maxlen/docker-howto","last_synced_at":"2025-05-03T21:31:16.881Z","repository":{"id":99102476,"uuid":"242756383","full_name":"maxlen/docker-howto","owner":"maxlen","description":"Fast howTo for Docker, Dockerfile, and Docker-Compose. Also Practical Hands-On Exercises.","archived":false,"fork":false,"pushed_at":"2025-03-11T13:43:41.000Z","size":1200,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T21:45:08.291Z","etag":null,"topics":["docker","docker-compose","dockerfile","maxlen","maxlenash","ml","udemy","udemy-course"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxlen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-24T14:23:59.000Z","updated_at":"2025-03-11T13:43:45.000Z","dependencies_parsed_at":"2023-06-03T20:15:09.063Z","dependency_job_id":null,"html_url":"https://github.com/maxlen/docker-howto","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxlen%2Fdocker-howto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxlen%2Fdocker-howto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxlen%2Fdocker-howto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxlen%2Fdocker-howto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxlen","download_url":"https://codeload.github.com/maxlen/docker-howto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252259305,"owners_count":21719659,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose","dockerfile","maxlen","maxlenash","ml","udemy","udemy-course"],"created_at":"2024-11-13T01:51:20.736Z","updated_at":"2025-05-03T21:31:16.875Z","avatar_url":"https://github.com/maxlen.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HowTo Docker\r\n\r\nDocker, Dockerfile, and Docker-Compose (2020 ready!)\r\n\r\nLearn Docker, Containers vs. Images, Dockerfile, Docker-Compose\r\n\r\nWith Practical Hands-On Exercises!\r\n\r\n![Scheme](./docker-logo.png)\r\n\r\n### based on video-course\r\nhttps://www.udemy.com/course/docker-and-docker-compose-hands-on-by-example/\r\n\r\nThomas Wiesner. Teaching over 60,000 Students about Development (https://www.facebook.com/tomscourses/)\r\n\r\n### What you will learn\r\n- You will learn to use Docker with Hands-On Demos and Exercises\r\n- Know the most important Docker-Run Flags and Everyday Use-Cases\r\n- Be able to read, understand and write your own Dockerfiles\r\n- Read and write your own docker-compose yaml files\r\n- Understand the difference between Host-Volume and Named-Volume mounting\r\n- Improve real-world docker-compose yaml files\\\r\n\r\n### Steps:\r\n- \u003cb\u003ePart 1 and 2\u003c/b\u003e: Introduction and install docker to desktop\r\n- \u003cb\u003ePart 3\u003c/b\u003e: Docker run and  docker commands\r\n- \u003cb\u003ePart 4\u003c/b\u003e: Dockerfile and docker commands\r\n- \u003cb\u003ePart 5\u003c/b\u003e: Docker-compose. Volumes and docker-compose + dockerfile\r\n- \u003cb\u003ePart 6\u003c/b\u003e: Networks and docker, docker-compose\r\n- \u003cb\u003ePart 7\u003c/b\u003e: Examples\r\n\r\n### Helpful documentation\r\n#### Docker:\r\nhttps://docs.docker.com/\r\n\r\nFor example \"MariaDB doc and env-variable\": https://hub.docker.com/_/mariadb\r\n#### docker-compose:\r\nhttps://docs.docker.com/compose/\r\n\r\nFor example \"Quickstart: Compose and WordPress\": https://docs.docker.com/compose/wordpress/\r\n\r\nor in DocherHub: https://hub.docker.com/_/wordpress\r\n\r\n### useful documentation:\r\ndockerfile best practices: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/\r\n\r\n\r\n\r\n# Fast HowTo (Docker, Dockerfile, docker-compose)\r\n\r\n## Main commands and features\r\n\r\n#### general commands with Docker\r\n```dotenv\r\n# show all containers\r\ndocker ps -a\r\n\r\n# build image with tag (with Dockerfile)\r\ndocker build -t myphpapp .\r\n\r\n# run docker-container from image ubuntu\r\ndocker run -it ubuntu /bin/bash\r\n\r\n# start docker-container when it stops\r\ndocker start container_name\r\n\r\n# attach docker-container (like exec + bash)\r\ndocker attach container_name\r\n\r\n# stop docker-container\r\ndocker stop container_name\r\n\r\n# remove docker-container\r\ndocker rm container_name\r\n\r\n# remove image\r\ndocker rmi image_name_or_tag\r\n\r\n# Run container from image 'ubuntu' in interactive mode (-it)\r\n# with attached volume 'my-vol' (-v)\r\n# with name linux1, detached\r\n# and remove the container when it will stop (--rm)\r\ndocker run -v my-vol:/my-data --rm -it -d --name linux1 ubuntu /bin/bash\r\n\r\n# run docker-container from image ubuntu with shared directory with host machine\r\ndocker run --rm -v ${PWD}:/myvol ubuntu /bin/bash -c \"ls -lha \u003e /myvol/myfile.txt\"\r\n\r\n# create container from image with port mapping and volume mointing\r\ndocker run -d --rm -p 8080:80 -v ${PWD}:/var/www/html php:7.4-apache\r\n\r\n```\r\n\r\n#### volumes\r\n```dotenv\r\n# create volume with name 'my-vol'\r\ndocker volume create --name my-vol\r\n\r\n# show all volumes\r\ndocker volume ls\r\n\r\n# remove volume with name 'my-vol' \r\ndocker volume rm my-vol\r\n```\r\n#### networks\r\n```dotenv\r\n# create network and start container which use this network\r\ndocker network create simple-network\r\ndocker run --rm -d --name my-webserver --network simple-network httpd\r\n\r\n# run docker container with port mapping\r\ndocker run -p 8080:8000 myphpapp:web\r\n\r\n# run container with port mapping and name\r\ndocker run --name myphp-apache -p 8080:80 myphpapp:apache\r\n\r\n# show all networks\r\ndocker network ls\r\n\r\n# remove volume with name 'my-vol' \r\ndocker network rm my-network\r\n\r\n# remove all networks not used by at least one container (now) \r\ndocker network prune\r\n```\r\n#### docker-compose commands\r\n```dotenv\r\n# start container/s and detach\r\ndocker-compose up -d\r\n\r\n# build/rebuild container\r\ndocker-compose up --build\r\n\r\n# list of started containers\r\ndocker-compose ps \r\n\r\n# stop and remove containers and networks\r\ndocker-compose down\r\n\r\n# build images without cache\r\ndocker-compose build --no-cache service1 service2\r\n\r\n```\r\n\r\n#### Dockerfile\r\n```dotenv\r\n# set image from dockerhub\r\nFROM php:7.4-apache\r\n\r\nRUN apt-get -y update \\\r\n\u0026\u0026 apt-get install -y libicu-dev \\\r\n\u0026\u0026 docker-php-ext-configure intl \\\r\n\u0026\u0026 docker-php-ext-install intl\r\n\r\nRUN docker-php-ext-install mysqli \u0026\u0026 docker-php-ext-enable mysqli\r\n\r\n# set file|catalog wich we use in web-server\r\nCOPY index.php /var/www/html\r\n\r\n# use port\r\nEXPOSE 8000\r\n\r\n# after container start\r\nCMD [\"php\", \"-S\", \"0.0.0.0:8000\"]\r\n\r\n```\r\n\r\n#### docker-compose.yml\r\n```dotenv\r\nversion: '3.7'\r\n\r\nservices:\r\n  web:\r\n    image: nginx:alpine\r\n    container_name: udemy-web\r\n    volumes:\r\n      - ./nginx.conf:/etc/nginx/nginx.conf\r\n    ports:\r\n      - 8090:80\r\n    networks:\r\n      - app1_net\r\n      - app2_net\r\n\r\n  app1:\r\n    image: httpd:latest\r\n    container_name: udemy-app1\r\n    networks:\r\n      - app1_net\r\n\r\n  app2:\r\n    image: httpd:latest\r\n    container_name: udemy-app2\r\n    networks:\r\n      - app2_net\r\n\r\nnetworks:\r\n  app1_net:\r\n  app2_net:\r\n```\r\n\r\n#### Examples\r\n```dotenv\r\n# EXAMPLE 1: (Lesson3.3-Shared-Volume-Mounting)\r\n\r\n# unpackage some archive throught container and remove it\r\n# https://hub.docker.com/r/klutchell/rar\r\n# flag -w for working directory (like cd)\r\ndocker run --rm -v ${PWD}:/files -w /files klutchell/rar a /files/myrar.rar /files/myfile.txt\r\n\r\n# EXAMPLE 2: (Part3-Docker-Run/Lesson3.4-PHP-with-volume-mounting)\r\n\r\n# PHP-with-volume-mounting\r\n# create container from php-image\r\ndocker run -it --rm -v ${PWD}:/my-files -w /my-files --name php-script php:7.4-cli /bin/bash\r\n\r\n# create php-file from console of container:\r\necho '\u003c?php echo \"ml test\";' \u003e index.php\r\n\r\n# exit from container and try to run:\r\ndocker run -it --rm -v ${PWD}:/my-files -w /my-files --name php-script php:7.4-cli php index.php\r\n\r\n# EXAMPLE 3:\r\n\r\n\r\n```\r\n\r\n#### Push image to docker-hub\r\n1. register or login in https://hub.docker.com/\r\n2. login to docker-hub in your pc [bash]:\r\n    ```dotenv\r\n    docker login\r\n    ``` \r\n3. create Dockerfile:\r\n    ```dotenv\r\n    FROM alpine\r\n    \r\n    RUN apk update \u0026\u0026 apk add curl;\r\n    \r\n    ENTRYPOINT [\"curl\"]\r\n    ``` \r\n4. in bash:\r\n    ```dotenv\r\n    docker run mycurl google.com\r\n    ```\r\n5. re-tag image:\r\n    ```dotenv\r\n    docker tag mycurl maxlenash/mycurl:latest\r\n    ```\r\n6. push image to docker-hub:\r\n    ```dotenv\r\n    docker push maxlenash/mycurl:latest\r\n    ```\r\n7. that's all. Now we can execute:\r\n    ```dotenv\r\n    docker run --rm maxlenash/mycurl google.com\r\n    ```\r\n8. remove unnecessary:\r\n    ```dotenv\r\n    docker rmi mycurl maxlenash/mycurl\r\n    ```\r\n   \r\n   \r\n#### Done\r\n\r\nAt the end of course you'll have certificate like that:\r\n\r\n![Scheme](./certificate.jpg)\r\n\r\n##### whoami\r\nThat git-repository created by Maxim Gavrilenko https://www.linkedin.com/in/maxim-gavrilenko\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxlen%2Fdocker-howto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxlen%2Fdocker-howto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxlen%2Fdocker-howto/lists"}