{"id":13415765,"url":"https://github.com/dwyl/learn-docker","last_synced_at":"2025-03-14T23:31:05.811Z","repository":{"id":20584513,"uuid":"23865141","full_name":"dwyl/learn-docker","owner":"dwyl","description":"🚢    Learn how to use docker.io containers to consistently deploy your apps on any infrastructure.","archived":false,"fork":false,"pushed_at":"2024-01-22T16:17:14.000Z","size":41,"stargazers_count":230,"open_issues_count":10,"forks_count":32,"subscribers_count":40,"default_branch":"master","last_synced_at":"2024-07-31T21:54:34.853Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dwyl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2014-09-10T07:32:34.000Z","updated_at":"2024-05-30T12:37:15.000Z","dependencies_parsed_at":"2024-02-09T01:55:13.902Z","dependency_job_id":"aadda0e2-c54a-46c5-b3f8-9b8819bf068a","html_url":"https://github.com/dwyl/learn-docker","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/dwyl%2Flearn-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwyl%2Flearn-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwyl%2Flearn-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwyl%2Flearn-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dwyl","download_url":"https://codeload.github.com/dwyl/learn-docker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243663450,"owners_count":20327299,"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":[],"created_at":"2024-07-30T21:00:51.962Z","updated_at":"2025-03-14T23:31:05.534Z","avatar_url":"https://github.com/dwyl.png","language":"Dockerfile","readme":"Docker: Believe the Hype!\n============\n\n![Docker Logo](http://i.imgur.com/KgdWLdh.png)\n\n\nLearn how to use docker.io containers to consistently deploy\nyour apps on any infrastructure.\n\n## Why?\nHave you ever struggled to get your developer environment set up as a new user on\nan existing project? Or have you ever had difficulty reproducing a bug or error\nthat another team member is experiencing? Or that only exists in your production\nenvironment but not in your development environment? If you have, then you have\nencountered some of the difficulties that can arise when code is run in different\nenvironments. Docker is the solution to these problems as well as\noffering a host of other benefits.\n\nDocker containers offer the isolated environment advantages of running a virtual\nmachine, but are more lightweight, portable, scalable and have less overhead/hassle.\n- reduce the delay between writing code and running it in production\n- automation of the environment set up saves time setting up new users and time\ntrying to reproduce bugs/errors\n- easily create [sandboxes](https://en.wikipedia.org/wiki/Sandbox_%28computer_security%29)\n- reduces ‘dependency hell’\n- easy to perform deployment rollbacks\n- Good for legacy, native, Linux and Windows based apps\n\n## What?\n- Docker’s official definition is that it’s ‘an open platform for developing,\nshipping, and running applications’.\n- It provides you with the ability to package and run an application in a loosely\nisolated environment called a container.\n- Your defined environment (dependency versions and environment variables) can\nthen be run by whomever is working on / viewing the application. This means that\neveryone can have the same experience.\n- To create this isolated environment for your application put it into a\n‘container’ (a standardised unit of software):\n\n[**Container**](https://www.docker.com/resources/what-container)\n\u003e A container is a standard unit of software that packages up code and all its\ndependencies so the application runs quickly and reliably from one computing\nenvironment to another.\n\n**Container image**\n\u003e A Docker container image is a lightweight, standalone, executable package of\nsoftware that includes everything needed to run an application: code, runtime,\nsystem tools, system libraries and settings. Container images become containers\nat runtime and in the case of Docker containers - images become containers when\nthey run on [Docker Engine](https://www.docker.com/products/docker-engine). \n\n- Read the *official* \"Docker overview\" (10 minute read):\nhttps://docs.docker.com/engine/docker-overview/\n- Watch this 12 minute video on what Docker is and a simple example of how to\nuse it: https://youtu.be/YFl2mCHdv24. Follow along with the example if you want\nto test it out for yourself!\n\n## How?\n\n### Installation\n\n+ Mac: https://docs.docker.com/docker-for-mac/install/\n+ Windows: https://docs.docker.com/docker-for-windows/install/\n+ Linux: you already have LXC but can install a native docker package\nby clicking \"Linux\" and selecting your distro from the list or installing\na binary: https://docs.docker.com/install/linux/docker-ce/binaries/\n\nMac example walk through:\n\n1. Create a Docker Hub account: https://hub.docker.com/ You need an account to\nbe able to download Docker Desktop. Docker Hub lets you store your docker files\n(public \u0026 private) so you can share these with people and deploy them anywhere.\n\n2. Download Docker Desktop for Mac: https://hub.docker.com/editions/community/docker-ce-desktop-mac\nThe file is **546.8MB** and you need Mac OS Sierra or later, and to have at\nleast 4GB of RAM.\n\n3. Install Docker Desktop on your Mac.\nOpen the `docker.dmg` file you downloaded, and drag the Docker app's whale icon\ninto your Applications folder.\n\n![drag-docker-to-applications](https://user-images.githubusercontent.com/16775804/54625627-8bdb4200-4a67-11e9-9b9d-891d20ea359c.png)\n\n4. Open and run Docker\nWhen you run the Docker app, a little whale icon will appear on the right-hand\nside of the menu bar at the top of your screen. It might take a few minutes to\nget running, and Docker may ask your permission to use services on your computer.\nThe app will also prompt you to enter your Docker Hub account details.\n\n\n## Once installed\n\nOnce you've installed Docker, opened it and signed in to your account you can\nnow open a command-line terminal, and try out some Docker commands.\n\n- Try `docker version` to check that you have the latest release installed.\n\n- Or run `docker run hello-world` to verify that Docker is pulling images and running as expected.\n\nYou should see something like this in your terminal:\n\n![docker-configured](https://user-images.githubusercontent.com/16775804/54629658-f2645e00-4a6f-11e9-8ce0-139243a022d6.png)\n\nAs it suggests, next try to run an ubuntu container (*only do this on a fast\n  internet connection as its going to download 65mb ubuntu image*)\n\n```sh\ndocker run -it ubuntu bash\n```\n![download ubuntu](https://user-images.githubusercontent.com/16775804/54629793-39eaea00-4a70-11e9-91c3-328132251a00.png)\n\nThis will boot the Ubuntu image and log you into the container's bash.\nYou can confirm that you are in a Linux bash by running the following\ncommand: `cat /etc/os-release`\n\n![confirm-running-ubuntu](https://user-images.githubusercontent.com/16775804/54629885-69015b80-4a70-11e9-976d-c25b34373a6a.png)\n\nList the containers:\n\n```sh\ndocker container ls\n```\nWhich shows:\n\n![docker-container-ls](https://user-images.githubusercontent.com/16775804/54669601-b241c180-4ae9-11e9-9bf5-e246b1cfa6aa.png)\n\nSee: https://docs.docker.com/engine/reference/commandline/container_ls/ for ways\nto make this command more specific.\n\nAnd for even more detail, run `docker info`\n\n```sh\nContainers: 2\nImages: 6\nStorage Driver: aufs\n Root Dir: /mnt/sda1/var/lib/docker/aufs\n Backing Filesystem: extfs\n Dirs: 10\n Dirperm1 Supported: true\nExecution Driver: native-0.2\nLogging Driver: json-file\nKernel Version: 4.0.9-boot2docker\nOperating System: Boot2Docker 1.8.1 (TCL 6.3); master : 7f12e95 - Thu Aug 13 03:24:56 UTC 2015\nCPUs: 1\nTotal Memory: 1.956 GiB\nName: default\nID: VIPW:LYBS:LT7I:KWTS:DU5U:W2NG:MWMH:EQNS:PFTF:4ZLN:STYL:4HG2\nDebug mode (server): true\nFile Descriptors: 9\nGoroutines: 20\nSystem Time: 2015-08-16T22:27:21.593654583Z\nEventsListeners: 0\nInit SHA1:\nInit Path: /usr/local/bin/docker\nDocker Root Dir: /mnt/sda1/var/lib/docker\nLabels:\n provider=virtualbox\n```\n\n\n\n### Run the `Dockerfile` in this repo\n\nFirst build the image:\n\n```sh\ndocker build -t learn-docker .\n```\nThen run the image as a container:\n```sh\ndocker run -it -p 8888:8888 learn-docker bash\n```\n\u003e https://docs.docker.com/v17.09/engine/reference/commandline/run/\n\nExec (for running a command in a running container)\n\n```sh\ndocker exec -it learn-docker bash\n```\n\u003e https://docs.docker.com/v17.09/engine/reference/commandline/exec/\n\n### List (*Locally Available*) Images\n\nView the current (*locally*) available docker images:\n```sh\n$ docker images\n```\n\nYou should see:\n\n```sh\nREPOSITORY          TAG                 IMAGE ID            CREATED                  VIRTUAL SIZE\nlearn-docker        latest              0c495aa0e6dc        Less than a second ago   261.6 MB\nubuntu              14.04               8251da35e7a7        8 days ago               188.4 MB\nubuntu              latest              8251da35e7a7        8 days ago               188.4 MB\nhello-world         latest              af340544ed62        9 days ago               960 B\n```\n\n### `docker ps`\n\nTo list all the running docker containers, use:\n\n```sh\ndocker ps -a\n```\n\n\u003e https://docs.docker.com/v17.09/engine/reference/commandline/ps/\n\n### More info on a specific container\n\nTo get more detail on a container type: `docker inspect {imageid}`\n\ne.g: in our case the container we are interested in has the id: **a205fc3a096f** so we run:\n```sh\ndocker inspect a205fc3a096f\n```\nThe complete output of this command is in:\n[/**sample-docker-inspect.txt**](https://github.com/dwyl/learn-docker/blob/e8769347940dc13d8197742b9e232e3efd85ca8d/sample-docker-inspect.txt)\n\n#### Just the IP address\n\nIf all we want is the container's IP address we run:  \n` docker inspect --format '{{ .NetworkSettings.IPAddress }}' a205fc3a096f`  \nwhere the last argument is the container (image) id.  \n\u003csmall\u003eCourtesy of: http://stackoverflow.com/a/20686101/1148249\u003c/small\u003e\n\n### Kill a Container by ID\n\n```sh\ndocker stop a205fc3a096f\n```\n\n\u003e https://docs.docker.com/v17.09/engine/reference/commandline/stop/\n\n## Help!\n\nFor some reason I'm unable to access the **nginx** server running inside the docker container ...\nlooked at:\n+ http://stackoverflow.com/questions/31324981/how-to-access-host-port-from-docker-container\n+ http://stackoverflow.com/questions/31448249/how-to-deploy-web-service-on-docker-container\n+ http://stackoverflow.com/questions/27714900/nginx-on-docker-daemonize-and-attach-to-bash\n\n### is nginx working?\n\n+ http://askubuntu.com/questions/443775/nginx-failing-to-reload-how-to-track-down-why\n\nTest that your nginx configuration is valid (doesn't have errors)\n```sh\nsudo nginx -t\n```\n\nexpect the following output:\n```sh\nnginx: the configuration file /etc/nginx/nginx.conf syntax is ok\nnginx: configuration file /etc/nginx/nginx.conf test is successful\n```\n\n## Docker and [\"PETE\" stack](https://github.com/dwyl/technology-stack#the-pete-stack)\n\nYou can create or run a Phoenix application by using the following Dockerfile:\n\n```\nFROM elixir:1.7.3\n\nRUN mix local.hex --force \\\n  \u0026\u0026 mix archive.install hex phx_new 1.4.0 --force \\\n  \u0026\u0026 apt-get update \\\n  \u0026\u0026 curl -sL https://deb.nodesource.com/setup_8.x | bash \\\n  \u0026\u0026 apt-get install -y apt-utils \\\n  \u0026\u0026 apt-get install -y nodejs \\\n  \u0026\u0026 apt-get install -y build-essential \\\n  \u0026\u0026 apt-get install -y inotify-tools \\\n  \u0026\u0026 mix local.rebar --force \\\n  \u0026\u0026 wget \"https://github.com/elm/compiler/releases/download/0.19.0/binaries-for-linux.tar.gz\" \\\n  \u0026\u0026 tar xzf binaries-for-linux.tar.gz \\\n  \u0026\u0026 mv elm /usr/local/bin/\n\nENV APP_HOME /app\nWORKDIR $APP_HOME\n\n\nCMD [\"mix\", \"phx.server\"]\n```\nThis will create a container with Elixir, Node.js, Elm.\n\nYou can then use the following `docker-compose.yml` file to use Postgres with your application:\n\n```\nversion: '3'\nservices:\n  app:\n    build: .\n    ports:\n      - \"4000:4000\"\n    volumes:\n      - .:/app\n    depends_on:\n      - db\n    env_file:\n      - ./.env\n  db:\n    image: postgres:10.5\n    ports:\n        - \"5432:5432\"\n```\n\nYou can then create a new Phoenix application with:\n`docker-compose run --rm app mix phx.new . --app name_of_the_app`\n\nMake sure to update the database configuration in the Phoenix application to reference the Postgres service name (ie db), for example:\n\n```elixir\n# Configure your database\nconfig :app_name, AppName.Repo,\n  username: \"postgres\",\n  password: \"postgres\",\n  database: \"app_name_dev\",\n  hostname: \"db\",\n  pool_size: 10\n```\n\nUse `docker-compose` if you want to run commands, for example to create the database:\n\n`docker-compose run web mix ecto.create`\n\n## Docker Swarm vs. Kubernetes\nThis repo has walked through the basic set up of Docker containers. To deal with\nmanaging multiple containers there are container management facilities or container\norchestration platforms. These facilities are useful for:\n\n- Running containers across many different machines\n- Scaling up or down by adding or removing containers when demand changes\n- Keeping storage consistent with multiple instances of an application\n- Distributing load between the containers\n- Launching new containers on different machines if something fails\n\nDocker offers its own such facility called [Docker Swarm](https://docs.docker.com/engine/swarm/).\nAnother popular open source platform is [Kubernetes](http://kubernetes.io/).\nKubernetes must be used in conjunction with Docker containers, it is not a\ncomplete alternative.\n\nDocker Swarm and Kubernetes both have their pros and cons. Deciding which one to\nuse comes down to what is best for your project. But as a very brief summary,\nDocker Swarm is considered easier to adopt with better usability than Kubernetes.\nWhilst slower to initially learn, Kubernetes receives praise for its ability to\nscale at speed for larger projects and its flexibility.\n\nTo find out more see:\n- https://blog.containership.io/k8svsdocker\n- https://technologyadvice.com/blog/information-technology/kubernetes-vs-docker/\n\n## Useful Links\n\n### About Docker\n- Light-hearted Slideshow (with adequate detail to read through it) about what\nDocker is and how it is useful: https://www.slideshare.net/jpetazzo/docker-automation-for-the-rest-of-us\n\n### Cheat Sheet\n\n- Command Line Reference: https://docs.docker.com/engine/reference/commandline/cli/\n- Cheat Sheet: https://github.com/wsargent/docker-cheat-sheet\n- Cheat Sheet: https://spacelift.io/blog/docker-commands-cheat-sheet\n\n### Videos\n\n- Introduction to Docker - (Twitter University):\nhttps://www.youtube.com/watch?v=Q5POuMHxW-0 47mins - 2mins of *content*!\n- Be a happier developer with Docker:\nhttps://www.youtube.com/watch?v=XCVOxht34Hs 25mins - relevant to developers\n\n### Tutorials\n- https://www.imore.com/how-run-docker-your-mac\n- http://blog.xebia.com/2014/06/18/deploying-a-node-js-app-to-docker-on-coreos-using-deis/\n","funding_links":[],"categories":["Uncategorized","介绍","Dockerfile"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwyl%2Flearn-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdwyl%2Flearn-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwyl%2Flearn-docker/lists"}