Skip to content

Instantly share code, notes, and snippets.

@imrodrigoalves
Created June 7, 2020 16:07
Show Gist options
  • Save imrodrigoalves/04817bd221346847649be906fbd1e1a2 to your computer and use it in GitHub Desktop.
Save imrodrigoalves/04817bd221346847649be906fbd1e1a2 to your computer and use it in GitHub Desktop.
## List Docker CLI commands
docker
docker container --help
## Display Docker version and info
docker --version
docker version
docker info
## Execute Docker image
docker run hello-world
## List Docker images
docker image ls
## List Docker containers (running, all, all in quiet mode)
docker container ls
docker container ls --all
docker container ls -aq
"" CREATING CONTAINERS ""
## Create image using this directory's Dockerfile
docker build -t friendlyhello .
## Run "friendlyhello" mapping port 4000 to 80
docker run -p 4000:80 friendlyhello
## Same thing, but in detached mode
docker run -d -p 4000:80 friendlyhello
## List all running containers
docker container ls
## List all containers, even those not running
docker container ls -a
## Gracefully stop the specified container
docker container stop <hash>
## Force shutdown of the specified container
docker container kill <hash>
## Remove specified container from this machine
docker container rm <hash>
## Remove all containers
docker container rm $(docker container ls -a -q)
## List all images on this machine
docker image ls -a
## Remove specified image from this machine
docker image rm <image id>
## Remove all images from this machine
docker image rm $(docker image ls -a -q)
## Log in this CLI session using your Docker credentials
docker login
## Tag <image> for upload to registry
docker tag <image> username/repository:tag
## Upload tagged image to registry
docker push username/repository:tag
## Run image from a registry
docker run username/repository:tag
"" MANAGING MULTIPLE CONTAINERS IN PROD AKA SERVICES ""
docker stack ls # List stacks or apps
docker stack deploy -c <composefile> <appname> # Run the specified Compose file
docker service ls # List running services associated with an app
docker service ps <service> # List tasks associated with an app
docker inspect <task or container> # Inspect task or container
docker container ls -q # List container IDs
docker stack rm <appname> # Tear down an application
docker swarm leave --force # Take down a single node swarm from the manager
docker exec -it [container-id] bash # execute running container
docker run -it --name admin -v volumename:/var/lib/docker/volumes/volumename/_data busybox # Check content of volume
docker-compose up --build -d SERVICE # Run docker composer and build image
docker-compose logs -f # Log follow all containers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment