{"id":19315745,"url":"https://github.com/alfahami/hands-on-docker","last_synced_at":"2026-05-08T06:19:57.922Z","repository":{"id":114226819,"uuid":"367598754","full_name":"alfahami/hands-on-docker","owner":"alfahami","description":"A cheat sheet and a beginner friendly walk through docker and it myriad functionalities.","archived":false,"fork":false,"pushed_at":"2021-07-25T19:42:48.000Z","size":279,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-06T03:42:52.710Z","etag":null,"topics":["alpine-linux","dangling-containers","dock-container","docker","docker-architecture","docker-compose","docker-containers","nginx-image","registry","rest-api"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/alfahami.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,"publiccode":null,"codemeta":null}},"created_at":"2021-05-15T10:10:54.000Z","updated_at":"2021-07-25T19:47:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"3186fbeb-176f-4eeb-977f-902bb81ecbd2","html_url":"https://github.com/alfahami/hands-on-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/alfahami%2Fhands-on-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfahami%2Fhands-on-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfahami%2Fhands-on-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfahami%2Fhands-on-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alfahami","download_url":"https://codeload.github.com/alfahami/hands-on-docker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240417402,"owners_count":19797980,"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":["alpine-linux","dangling-containers","dock-container","docker","docker-architecture","docker-compose","docker-containers","nginx-image","registry","rest-api"],"created_at":"2024-11-10T01:08:06.946Z","updated_at":"2026-05-08T06:19:52.879Z","avatar_url":"https://github.com/alfahami.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"### DOCKER CHEAT SHEET\nIn this cheat sheet, I'll be using \u003ccode\u003eapache\u003c/code\u003e image and \u003ccode\u003ephp\u003c/code\u003e.\nAt the end we'll build a **_multi-staged_** php mvc news app with Docker.\n\n#### \u003cu\u003eBASICS COMMANDS\u003c/u\u003e\n* Container's ID\n\nThe CONTAINER ID is the first 12 characters of the full container ID printed out after running \u003ccode\u003edocker container run\u003c/code\u003e.\\\nThe NAME is generated by docker and can be renamed by user later.\n* Create a container with a custom name and publish it to a port\u003ccode\u003e\\\u003chost-port:container-port\u003e\u003c/code\u003e without running.\n```\ndocker create --pulblish | -p 8080:80 --name apache-server httpd \n8fad9d84692858682f33ff2b60d3ee43e946af96d062c1fb3aa399ea082e5345\n```\n* Running a container (\u003ccode\u003ecreate\u003c/code\u003e and \u003ccode\u003estart\u003c/code\u003e)\n```\ndocker container run -p 8080:80 --name apache-server httpd \n\n# or we don't have to precise \"container\"\n\ndocker run -p 8080:80 --name apache-server httpd\n```\n* Naming and renaming a container\n```\ndocker container run --detach --publish 8080:80 --name apache-server httpd\n\n# Renaming\n\ndocker container rename \u003ccontaienr ID\u003e \u003cnew name\u003e\n```\n* Running a container in the background\n```\ndocker container run --detach | -d -p 80800:80 --name apache-server\n```\n* Running a container interactively \n```\ndocker container run -it | --interactive --tty\n#\ndocker container run -it ubuntu \n```\n* Starting and restarting a container\n```\ndocker container start apache-server | \u003ccontainer ID=output of previous command\u003e\napache-server\n```\n* Stopping a container (send a \u003ccode\u003e_SIGTERM_\u003c/code\u003e signal)\n```\ndocker container stop apache-server # or container ID\n```\n* Restarting a stopped container\n```\ndocker container restart apache-server # or container ID\n```\n* Killing a container (send a \u003ccode\u003e_SIGKILL_\u003c/code\u003e signal)\n```\ndocker container kill apache-server # once killed it can't be restarted\n```\n* Running and stopping (\u003ccode\u003e_SIGTERM_\u003c/code\u003e) a container after \u003ccode\u003eCtrl + C\u003c/code\u003e\n```\ndocker container run --rm -it ubuntu\n```\n* Removing a stopped \u003ccode\u003e_SIGTERM_\u003c/code\u003e container\n```\ndocker container rm | -f \u003ccontainer ID | name\u003e\n#\ndocker container rm apache-server\n```\n* Removing all dangling (stopped \u003ccode\u003e_SIGTERM_\u003c/code\u003e) containers \n```\ndocker container prune\n```\n* Listing runnning containers\n```\ndocker container ps | ls\n```\n* Remove unused data\n```\ndocker system prune\n```\n\nRemove all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes.\n\n* Listing running and stopped containers\n```\ndocker container ps -a | --all | ls -a | ls --all\n```\n* Executing command inside a container (image configured to receive arguments)\n```\ndocker container run --rm alpine uname a\nLinux 094a0cbf37ad 4.19.0-16-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 Linux\n```\nIn the command above the uname -a is passed through the alpine image and get executed.\n\n* Bind Mounts for executable images but not only\n\nWhen you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its absolute path on the host machine. \n\n```\ndocker run -d -it --name devtest --mount type=bind,source=\"$(pwd)\"/target,target=/app nginx:latest\n```\nUsing the \u003ccode\u003e--volume | -v\u003c/code\u003e flag.\n```\ndocker run -d -it --name devtest -v \"$(pwd)\" target:/app nginx:latest\n\n# this command will let us verify if the bind mount was created correctly\n\ndocker inspect devtest (container name)\n```\n* Inspecting a Docker object\n\nReturn low-level information on Docker Objects. It provides detailed information on constructs controlled by Docker.\n```\ndocker inspect [OPTIONS] NAME[ID] [NAME | ID ...]\n```\n#### IMANGE MANIPULATIONS\n\nAccording to the [officail docs](https://docs.docker.com/engine/reference/builder/)\n\u003cblockquote\u003e\nDocker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.\n\u003c/blockquote\u003e\n\n* Creating images\n```\n# Make sure we're in the same folder as the Dockerfile \n\ndocker image buld -t \u003cimage-name\u003e build . \n\n# \u003cimage-name\u003e will be used to run the built image.\n# . indicate the build to be run from the current directory where Dockerfile exists.\n```\n* Our image should have httpd pre-installed \n* The image should start apache server upon running\n\n* Dockerfile\n```\n#base image \nFROM debian:latest \n\nRUN apt-get update \nRUN apt-get install apache2 -y \nRUN apt-get clean\n\nCOPY index.html /var/www/html/\n\nEXPOSE 80\n\n# running apache in foreground\nCMD [\"apache2ctl\", \"-D\", \"FOREGROUND\"] \n```\n* Tagging an image (assigning a custom identifier to our image)\n```\ndocker image build -t (--tag) \u003cimage-repository\u003e:\u003cimage tag name\u003e \u003cpath\u003e\n\n# example\n\ndocker image build --tag custom-apache:packaged httpd:packaged .\n```\n\n* Changing the tag of an already tagged built image\n```\ndocker image tag \u003cimage id\u003e \u003cimage repository\u003e:\u003cimage tag\u003e\n\n## or ##\n\ndocker image tag \u003cimage repository\u003e:\u003cimage tag\u003e \u003cnew image repository\u003e:\u003cnew image tag\n```\n* Listing and removing docker images\n```\n# listing all available images\ndocker image ls\n\n# removing one given image\ndocker image rm \u003cimage identifier or image name\u003e\n\n#removing all existing images\ndocker image prune | --force (-f) | --all (-a)\n```\n\n* Show the history of an image\n\n```\ndocker image history [OPTIONS: --human (-H) | --format | --no-trunc | --quiet (-q)] image\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falfahami%2Fhands-on-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falfahami%2Fhands-on-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falfahami%2Fhands-on-docker/lists"}