trallard
11/20/2017 - 3:12 PM

Docker cheat sheet

docker build -t friendlyname .  # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyname  # Run "friendlyname" mapping port 4000 to 80
docker run -d -p 4000:80 friendlyname         # Same thing, but in detached mode
docker container ls                                # List all running containers
docker container ls -a             # List all containers, even those not running
docker container stop <hash>           # Gracefully stop the specified container
docker container kill <hash>         # Force shutdown of the specified container
docker container rm <hash>        # Remove specified container from this machine
docker container rm $(docker container ls -a -q)         # Remove all containers
docker image ls -a                             # List all images on this machine
docker image rm <image id>            # Remove specified image from this machine
docker image rm $(docker image ls -a -q)   # Remove all images from this machine
docker login             # Log in this CLI session using your Docker credentials
docker tag <image> username/repository:tag  # Tag <image> for upload to registry
docker push username/repository:tag            # Upload tagged image to registry
docker run username/repository:tag                   # Run image from a reg

docker run -d image # run image
docker ps # see all the containers running
docker run -d --name redisHostPort -p 6379:6379 redis:latest # runs the container in detached mode and exposes the port
docker run -it -p 8787:8787 --name hello trallad/hello
docker run -d -p 8787:8787 -v $(pwd):/home/rstudio rocker/rstudio # link a local volume to the studio container 
docker build --rm --force-rm -t trallard/container .  # builds the image from the souce path and removes the container once exited

docker inspect --format='{{.Id}} {{.Parent}}' \
    $(docker images --filter since=f50f9524513f --quiet)

docker images --format '{{.Size}}\t{{.Repository}}\t{{.Tag}}\t{{.ID}}' | sed 's/ //' | sort -h -r | column -t  # sort Docker images per size