Docker Cookbook: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
| (7 intermediate revisions by the same user not shown) | |||
| Line 5: | Line 5: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[https://stackoverflow.com/a/16842203 Other helpful commands for viewing containers]. | |||
== Removing containers == | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
$ docker stop | $ docker stop [CONTAINER_ID] | ||
$ docker rm [CONTAINER_ID] | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== Managing images == | |||
List all images: <ref>[https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes How To Remove Docker Images, Containers and Volumes] - Digital Ocean</ref> | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
$ docker | $ docker images -a | ||
</syntaxhighlight> | |||
Remove an image: | |||
<syntaxhighlight lang="bash"> | |||
$ docker rmi [IMAGE_NAME] | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Clean up any resources — images, containers, volumes, and networks — that are dangling (not associated with a container): | |||
<syntaxhighlight lang="bash"> | |||
$ docker system prune | |||
</syntaxhighlight> | |||
To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command: <ref>[https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes How To Remove Docker Images, Containers, and Volumes]- DigitalOcean</ref> | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
$ docker | $ docker system prune -a | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 34: | Line 47: | ||
Exit the connection and return to the regular local filesystem command prompt with `exit`. | Exit the connection and return to the regular local filesystem command prompt with `exit`. | ||
== Copying files from Docker container to host == | |||
[https://docs.docker.com/engine/reference/commandline/cp/ docker cp] <ref>[https://docs.docker.com/engine/reference/commandline/cp/ docker cp] - Docker Documentation</ref> | |||
<pre> | |||
$ docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|- | |||
</pre> | |||
== See also == | == See also == | ||
Latest revision as of 17:34, 16 May 2021
View all running containers[edit]
$ docker ps
Other helpful commands for viewing containers.
Removing containers[edit]
$ docker stop [CONTAINER_ID] $ docker rm [CONTAINER_ID]
Managing images[edit]
List all images: [1]
$ docker images -a
Remove an image:
$ docker rmi [IMAGE_NAME]
Clean up any resources — images, containers, volumes, and networks — that are dangling (not associated with a container):
$ docker system prune
To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command: [2]
$ docker system prune -a
Viewing files in a container[edit]
$ docker exec -t -i mycontainer /bin/bash
Exit the connection and return to the regular local filesystem command prompt with exit.
Copying files from Docker container to host[edit]
$ docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
See also[edit]
- ↑ How To Remove Docker Images, Containers and Volumes - Digital Ocean
- ↑ How To Remove Docker Images, Containers, and Volumes- DigitalOcean
- ↑ docker cp - Docker Documentation