$ docker build -t {my_tag_name} --build-arg SSH_KEY="`cat ~/.ssh/id_rsa`" --no-cache .
$ docker image ls
or
$ docker images
- List all images including intermediate ones
$ docker images -a
$ docker image prune
- Options
-aprune not only dangling but also currently un-referenced images--filter "until=12h"only remove images created before 12h--filter "label=<key>"or--filter "label!=<key>"
$ docker image rm {image ID} {image ID2}
or
$ docker rmi {image ID} {image ID2}
- List running containers
$ docker ps
-
useful flages
-aList all containers both running and stopped-qquiet (only shows the container IDs)
-
New syntax to list containers
$ docker container ls
$ docker run {Image name}
- Options (goes before image name)
--namename the container--rmremove the container when it exits-it shinteractive and use shell in the container-ddetached mode
$ docker start {container ID}
- Stop specific containers
$ docker stop {Container ID 1} {Container ID 2}
or
$ docker kill {Container ID}
- Stop all running containers
$ docker stop $(docker ps -aq)
- Remove specific containers
$ docker container rm {Container ID 1} {Container ID 2} ...
- List all stopped containers
$ docker container ls -a --filter status=exited --filter status=created
- Remove all containers (the running ones will not be stopped and give an error)
$ docker rm $(docker ps -aq)
- Execute shell script in a Node container
$ docker exec -it {container ID} sh
- Execute the psql shell inside a postgres docker container
$ docker exec -it {container ID} psql -U postgres
$ docker logs {container ID} -f
-ffollow the output so that the logs keep coming
$ docker volume ls
$ docker volume rm {VOLUME NAME}
$ docker volume prune
$ docker network ls
- Remove a specific network
$ docker network rm {network id}
- Remove unused network
$ docker network prune
- Remove with filter
$ docker network prune -a --filter "until=12h"
$ docker system prune -f