Skip to content

Instantly share code, notes, and snippets.

@greatsharma
Created June 22, 2020 05:08
Show Gist options
  • Save greatsharma/de2a3e0ed9eff323959fb6fc3a976e2e to your computer and use it in GitHub Desktop.
Save greatsharma/de2a3e0ed9eff323959fb6fc3a976e2e to your computer and use it in GitHub Desktop.
Some important docker commands
* sudo systemctl status docker [check whether docker is running]
* getent group docker [check whether we are the memeber of the group, if not then we need
to add in the group to run docker commands]
* to add in docker group
sudo usermod -aG docker ${USER}
su - ${USER}
* docker pull image_name [pull the image]
* docker run image_name [run a container from an image]
* docker run image_name:tag
* docker run image_name command [run docker container with a command]
* docker run --name container_name image_name [run a named container from an image]
* docker run -d image_name [run container in backend i.e., dettached mode]
* docker run -v /full/local/path:/mounted/dir/in/container [mount data volume in docker]
* docker run -p host_port:container_port [port forwarding]
* docker attach container_name [attach to the container running in backend, works only for running containers]
* docker run --name container_name -it ubuntu [for running bash while creating the container]
* docker exec -it container_id/name bash [running bash in another terminal for a running ubuntu container,
works only for running containers]
* It's not possible to enter a stopped container, because the processes are gone, and therefore, the namespac-
es are gone as well.
* docker start -ia container_id/name [to start a stoped container]
* docker stop container_id/name
* -i [flag i for interactive mode]
* -e [flag for env var]
* docker ps [list all running containers]
* docker ps -a [list all containers]
* docker inspect container_name/id [details of the container]
* docker logs container_name [all logs of the container]
* docker history image_name
* docker stop container_id/container_name
* docker rm container_id/container_name [delete container permanantely]
* docker images [list of available images on the host]
* docker rmi image_id/image_name [remove image, first delete all containers made from this image]
* docker exec container_name command [execute command on the container]
* docker volume ls [data dir, local docker volume]
* docker volume rm volume-name [remove volume only if container is removed]
* docker build -t image_name -f mpath/to/dockerfile . [build custom docker images]
* docker login --username=yourhubusername [login to dockerhub]
* docker tag image_name/id yourhubusername/image_name:version [give version to image]
* docker push yourhubusername/image_name:version [push your custom image to dockerhub]
* docker inspect container_name [return low-level info on docker objects]
* docker logs container_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment