Container Commands
- $ docker - lists all available commands
- $ docker run [image name] - runs image (pulls if not local), creates/starts container
- $ docker run -it -p 8080:3000 tomcat:8.0 -create & start container from image
- $ docker start [cont ID] - starts an existing container
- $ docker stop [cont ID] - stops a container (does NOT delete)
- $ docker rm [cont ID] - deletes. Add -f tag if need to force
- $ docker ps - lists all containers running
- $ docker ps -a - list all containers (running & stopped)
- $ docker logs [cont ID] - show logs of running container
- $ docker inspect <cont> - shows info on container (JSON) or image
- $ docker run <image-name> sleep 1000 - stop container after 1,000 seconds
- $ docker network ls - list docker networks
- $ docker network inspect [ID] - network info (including containers in it)
- $ docker exec [cont ID] xyz - execute command in running container
- $ docker exec -it <cont_id> command - “ “ & enter interactive mode
- $ docker exec d64 node seed.js - as if in console (d64 $ node seed.js)
- $ docker exec d64 bash - gain access to container’s bash shell
- $ docker exec -it d64 /bin/bash - enter container d64 & attach bash shell
- $ docker rm 198.. - deletes container (only if it is stopped)
- $ docker rm -f 198 - removes/force deletes container (even if running)
- docker stop $(docker ps -a -q) - stop ALL containers
- $ docker rm $(docker ps -a -q) - delete ALL stopped container
- $ docker system prune - delete ALL unused data (stopped cont, vol w/o container & images w/ no cont)
- --rm → remove container when stopped
- --name <contName> → name the container once it is built from image