docker run --name ubuntu_bash --rm -i -t ubuntu bash
This will create a container named ubuntu_bash and start a Bash session.
docker exec -t <container_id> bash
Execute an interactive bash shell on the container:
docker ps -aqf "name=containername"
Shows container's id
docker start <container_id>"
Starts stopped container
docker ps -a
Lists containers (and tells you which images they are spun from)
docker stop <container_id>
Stops a container
docker rm <container_id>
Removes a stopped container
docker rm -f <container_id>
Forces the removal of a running container (uses SIGKILL)
docker rm -f <container_id>
Delete all containers that are not running.
docker images
Lists images
docker rmi <image_id>
Removes an image. Will fail if there is a running instance of that image i.e. container
docker image rm <image_name>
Removes an image
docker image rm -d <image_name>
Forcibly delete an image
docker container rm $(docker ps -a -q)
Kill all running containers.
docker container kill $(docker ps -q)
Kill all stopped containers, all networks not used by at least one container, all dangling images. all build cache
docker system prune
Forces removal of image even if it is referenced in multiple repositories, i.e. same image id given multiple names/tags. Will still fail if there is a docker container referencing image
docker run -p 8080:80 -p 5000:80 -d <image_name>
It will create a container and maps differenct localhost ports to the main container's port
docker ps --format "table ID\t{{.ID}}\nNAME\t{{.Names}}\nIMAGE\t{{.Image}}\nPORTS\t{{.Ports}}\nCOMMAND\t{{.Command}}\nCREATED\t{{.CreatedAt}}\nSTATUS\t{{.Status}}\n"
Cannot create container for service db: status code not OK but 500: {"Message":"Unhandled exception: Filesharing has been cancelled","StackTrace":" at Docker.ApiServices.Mounting.FileSharing.d__6.MoveNext()
(For Docker Desktop (windows)) The solution is to share the project path folder drive in Docker for starter. If that doesn't work, restart docker.
Found an amazing video from "FreeCodeCamp" about this topic: https://www.youtube.com/watch?v=-ANCcFQBk6I&ab_channel=freeCodeCamp.org