{"id":18843271,"url":"https://github.com/helton/docker-cheat-sheet","last_synced_at":"2026-01-31T08:30:17.148Z","repository":{"id":69061299,"uuid":"72477295","full_name":"helton/docker-cheat-sheet","owner":"helton","description":":whale: Docker Cheat Sheet - List of useful commands","archived":false,"fork":false,"pushed_at":"2016-11-03T02:35:31.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-30T12:25:27.673Z","etag":null,"topics":["docker","dockerfile"],"latest_commit_sha":null,"homepage":"","language":null,"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/helton.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":"2016-10-31T20:56:06.000Z","updated_at":"2017-10-26T15:17:15.000Z","dependencies_parsed_at":"2023-09-14T21:34:25.388Z","dependency_job_id":null,"html_url":"https://github.com/helton/docker-cheat-sheet","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/helton%2Fdocker-cheat-sheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helton%2Fdocker-cheat-sheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helton%2Fdocker-cheat-sheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helton%2Fdocker-cheat-sheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/helton","download_url":"https://codeload.github.com/helton/docker-cheat-sheet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239780138,"owners_count":19695736,"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","dockerfile"],"created_at":"2024-11-08T02:57:23.417Z","updated_at":"2026-01-31T08:30:17.083Z","avatar_url":"https://github.com/helton.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker Cheat Sheet\n\nList of useful Docker commands.\n\n\n### Show the Docker version:\n`docker version`\n\n### Show the Docker info:\n`docker info`\n\n### Pull an image from Docker Hub:\n`docker pull \u003cimage\u003e`\n#### Examples:\n```\ndocker pull alpine\ndocker pull node\n```\n\n### List all images stored locally:\n`docker images`\n\n### List all images layers stored locally:\n`docker images -q`\n\n### List all running containers:\n`docker ps`\n\n### List all containers:\n`docker ps -a`\n\n### List all containers id:\n`docker ps -aq`\n\n### Filter containers by status:\n`docker ps -f status=\u003cstatus\u003e`\n#### Examples:\n```\ndocker ps -f status=created\ndocker ps -f status=exited\n```\n\n### Remove container and the images associated with it:\n`docker rmi \u003cimage\u003e`\n#### Example:\n`docker rmi hello-world`\n\n### Remove just the container:\n`docker rm \u003ccontainer id\u003e`\n#### Example:\n`docker rm 9faaefb4a255`\n\n### Create and run a container (it'll download the image if it was not found locally):\n`docker run \u003cimage\u003e`\n#### Example:\n`docker run hello-world`\n\n### Create and run a container, removing it afterwards:\n`docker run --rm busybox date`\n\n### Start a container:\n`docker start \u003ccontainer id/name\u003e`\n#### Example:\n`docker start 9faaefb4a255`\n\n### Stop a container:\n`docker stop \u003ccontainer id/name\u003e`\n#### Example:\n`docker stop 9faaefb4a255`\n\n### Pause a container:\n`docker pause \u003ccontainer id/name\u003e`\n#### Example:\n`docker pause 9faaefb4a255`\n\n### Unpause a container:\n`docker unpause \u003ccontainer id/name\u003e`\n#### Example:\n`docker unpause 9faaefb4a255`\n\n### Restart a container:\n`docker restart \u003ccontainer id/name\u003e`\n#### Example:\n`docker restart 9faaefb4a255`\n\n### Attach terminal to a running container\n`docker attach \u003ccontainer id/name\u003e`\n#### Examples:\n```\ndocker attach 59c8b1bba36f\ndocker attach web\n```\n### Remove all containers at once! It pipes all containers id to the `docker rm` command:\n`docker rm $(docker ps -aq)`\n\n### Remove all exited containers:\n`docker rm $(docker ps -qf status=exited)`\n\n### Run a container assigning a name to it:\n`docker run hello-world --name hello`\n\n### Running a container in interactive mode:\n`docker run -it \u003ccontainer id/name\u003e`\n#### Example:\n`docker run -it centos /bin/bash`\n\n### Pull all versions of an image from Docker Hub:\n`docker pull -a \u003cimage\u003e`\n#### Example:\n`docker pull -a ubuntu`\n\n### Search all versions of an image from local store:\n`docker images \u003cimage\u003e`\n#### Example:\n`docker images ubuntu`\n\n### Search all versions of an image on Docker Hub:\n`docker search \u003cimage\u003e`\n#### Example:\n`docker search mysql`\n\n### Pull an image from Docker Hub with a specific version:\n`docker pull \u003cimage\u003e:\u003cversion\u003e`\n#### Example:\n`docker pull ubuntu:16.04`\n\n### Building an image based on a dockerfile:\nIf you are not on the same directory of the dockerfile, change the `.` to match the correct path to it:\n`docker build -t my-busybox .`\nIt's a good practice to attach a tag on your new image. To do so, run this command instead:\n`docker build -t my-busybox:latest .`\nNow just create a container with your brand new image:\n`docker run --rm my-busybox:latest`\n\n### Exit container without killing it:\n*A container contains a single process. If you kill this process, it'll have no more process running, killing the container as well. The command below make sure that the container will still be running after you detach your terminal from it:*\n\n=\u003e Press \u003ckbd\u003eCtrl\u003c/kbd\u003e + \u003ckbd\u003eP\u003c/kbd\u003e + \u003ckbd\u003eQ\u003c/kbd\u003e\n\n## Dockerfile\n\n### Examples (hopefully following the [Best practices for writing Dockerfiles](https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/))\n*Note:* To run the commands below to build the images and create the containers make sure you're on `dockerfiles` directory on this repository. If desired, a full path to the dockerfile can be specified.\nAll commands here:\n* build an image based on a dockerfile\n* create a container to run it\n* remove the container\n* remove the built image\nCheckout the [Dockerfile reference](https://docs.docker.com/engine/reference/builder/) for more details about the *Dockerfile*.\n\n#### 1) Create an image based on busybox:latest and show the current date:\n```\nFROM busybox:latest\nMAINTAINER Helton Carlos de Souza \u003chelton.development@gmail.com\u003e\nCMD [\"date\"]\n```\n##### Building and running it:\n```\ndocker build -t h3170n/busybox-show-date:latest ./busybox-show-date/ \u0026\u0026 \\\ndocker run --rm h3170n/busybox-show-date:latest \u0026\u0026 \\\ndocker rmi h3170n/busybox-show-date:latest\n```\n\n#### 2) Create an image based on alpine:latest and print `Hello, World` to the console:\n```\nFROM alpine:latest\nMAINTAINER Helton Carlos de Souza \u003chelton.development@gmail.com\u003e\nENTRYPOINT [\"/bin/echo\"]\nCMD [\"\\\"Hello, World\\\"\"]\n```\n##### Building and running it:\n```\ndocker build -t h3170n/alpine-hello-world:latest ./alpine-hello-world/ \u0026\u0026 \\\ndocker run --rm h3170n/alpine-hello-world:latest \u0026\u0026 \\\ndocker rmi h3170n/alpine-hello-world:latest\n```\n\n#### 3) Create an image based on alpine:latest and print the distro version to the console:\n```\nFROM alpine:latest\nMAINTAINER Helton Carlos de Souza \u003chelton.development@gmail.com\u003e\nENTRYPOINT [\"/bin/cat\"]\nCMD [\"/etc/lsb-release\"]\n```\n##### Building and running it:\n```\ndocker build -t h3170n/alpine-show-distro:latest ./alpine-show-distro/ \u0026\u0026 \\\ndocker run --rm h3170n/alpine-show-distro:latest \u0026\u0026 \\\ndocker rmi h3170n/alpine-show-distro:latest\n```\n\n#### 4) Create an image based on ubuntu:16.10 and install nginx:\n```\nFROM ubuntu:16.10\nMAINTAINER Helton Carlos de Souza \u003chelton.development@gmail.com\u003e\nRUN apt-get update \u0026\u0026 apt-get install -y nginx\n```\n##### Building and running it:\n```\ndocker build -t h3170n/ubuntu-install-nginx:latest ./ubuntu-install-nginx/ \u0026\u0026 \\\ndocker run --rm h3170n/ubuntu-install-nginx:latest \u0026\u0026 \\\ndocker rmi h3170n/ubuntu-install-nginx:latest\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelton%2Fdocker-cheat-sheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhelton%2Fdocker-cheat-sheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelton%2Fdocker-cheat-sheet/lists"}