Test if Docker installation is working
docker run hello-world
Run an Ubuntu container and open shell
docker run -it ubuntu /bin/bash
Run an Ubuntu container and mount an external directory to access it from the inside
Mount current directory ($PWD
):
docker run -v $PWD:/files -it ubuntu /bin/bash
Mount another directory using its path:
docker run -v /path/to/files:/files -it ubuntu /bin/bash
Automatically kill (remove) containers after the shell process dies (or generally after the container exits)
Use --rm
flag in docker run
.
List running containers
docker ps
List running and zombie containers
docker ps -a
Kill a zombie container
docker rm <container_id>
Container ID doesn't have to be the full ID, just needs to be the first few charactesr so that it's unique enough.
Save a container as a new image so that any changes are persisted and you can use this image for new containers later
docker commit <container_id> my_awesome_image
docker images # lists all images, should display your new image in the list
Delete an image
docker image rm <image_name>
docker image rm <image_id>
Again, image ID doesn't have to be the full ID, just first few characters is enough in most cases.