1. List all docker containers
docker container ls
2. List all images
docker image ls
docker images
3. Spawn & run from an image, a new container.
docker run image_name COMMAND
Example: docker run -ti ubuntu bash
Note (1) : The tag "latest" is automatically used if no tag is specified.
Note (2) : If the image is not locally available, then it will be downloaded.
Note (3) : To exit from container, press CTRL+D or type 'exit'.
4. Useful arguments with the docker run command
- -t : Run in a terminal
- -I : Interactive mode
- --rm : Run and then, delete this container when it exits.
- -d : Detached . To run container and leave it running in the background.
5. See all running containers
docker ps
6. See the last container that was run/exited.
docker ps -l
Note: Containers are not deleted automatically .
7. See all stopped containers list.
docker ps -a
8. Commit the changes you made to the container.
docker commit container_id (or NAMES . Get that using docker ps -l command)
Note: This does not change the container specifies her , BUT it creates a new image out of it.
The id of this new IMAGE , is returned to us after the commit.
Run "docker images" to see this new image in the list.
9. Add a tag to an image.
docker tag image_id some_name
10. Commit changes and tag container together.
docker commit container_id image_name
11. Working on a detached container.
docker attach container_id or name
Note: To exit (but not kill . Just leave it again running in the background) , press the key sequence:
Ctrl + p Ctrl + q
12. Run some extra command/process on the running container
docker exec
Example: docker exec -ti container_id/name COMMAND
Note: Do the above on a new terminal. You probably are already in the attached state to the same container on a different terminal.
13. Stop a container.
docker container stop container_id
14. Delete/remove a container.
docker container rm container_id
docker image rm <Image Name>
16. Remove all unused containers
docker container prune
17. See general info about docker and its status on your system
docker info
18. Docker Volumes.
We sometimes use volumes to store data. They can accumulate over time.
- Cleaning volumes
docker volume prune - Listing volumes
docker volume list - Inspect the contents of a volume.
docker volume inspect newfastapiproj_postgres_data
No comments:
Post a Comment