Skip to content

shihlun1208/Docker-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Docker-Cheatsheet

First of all, thanks to these great cheat sheets.

Dockerfile

The configuration file. Sets up a Docker container when you run docker build on it. Vastly preferable to docker commit.

Instructions

  • .dockerignore
  • FROM Sets the Base Image for subsequent instructions.
  • MAINTAINER (deprecated - use LABEL instead) Set the Author field of the generated images.
  • RUN execute any commands in a new layer on top of the current image and commit the results.
  • CMD provide defaults for an executing container.
  • EXPOSE informs Docker that the container listens on the specified network ports at runtime. NOTE: does not actually make ports accessible.
  • ENV sets environment variable.
  • ADD copies new files, directories or remote file to container. Invalidates caches. Avoid ADD and use COPY instead.
  • COPY copies new files or directories to container. By default this copies as root regardless of the USER/WORKDIR settings. Use --chown=<user>:<group> to give ownership to another user/group. (Same for ADD.)
  • ENTRYPOINT configures a container that will run as an executable.
  • VOLUME creates a mount point for externally mounted volumes or other containers.
  • USER sets the user name for following RUN / CMD / ENTRYPOINT commands.
  • WORKDIR sets the working directory.
  • ARG defines a build-time variable.
  • ONBUILD adds a trigger instruction when the image is used as the base for another build.
  • STOPSIGNAL sets the system call signal that will be sent to the container to exit.
  • LABEL apply key/value metadata to your images, containers, or daemons.
  • SHELL override default shell is used by docker to run commands.
  • HEALTHCHECK tells docker how to test a container to check that it is still working.

Docker Commands

Docker info

Command Description
docker version provides full description of docker version
docker -v provides a short description of docker version
docker info display system wide information
docker info --format '{{.DriverStatus}}' display 'DriverStatus' fragment from docker information
docker info --format '{{json .DriverStatus}}' display 'DriverStatus' fragment from docker information in JSON format
docker version --format '{{.Server.Version}}' display the server version
Command Description
docker images shows all images
docker rmi $(docker images -q) remove all images
docker rmi -f [image-name] force remove an image by name
docker image rm [image-name] remove image by name
Command Description
docker run --name [container-name] [image-name] Specific container name
docker run --name [container-name] -d [image-name] Specific container name, return container ID
docker run --name [container-name] -it [image-name] Specific container name, access container shell
winpty docker run -it {Image name} (Git Bash)
docker container run --rm [image-name] Run container based on specified imaged and immediately remove it once it stops
docker run -it -v [volume-name]:[container-mount-path] [image-name] Run container and bind mount volume
Command Description
docker ps -a List all containers
docker ps --filter status=running Check container status which is running
docker stop $(docker ps --filter status=running -q) Stop container which is running
docker stop $(docker ps -aq) Stop all running containers
docker rm $(docker ps -aq) Remove all containers
docker rm [container-ID] Remove container by ID
docker rm [container-name] Remove container by container name
docker exec -u 0 -it [container-ID] /bin/bash Run a existing container, access container shell with user root
Command Description
docker volume create [volume-name] Create volume
docker volume inspect [volume-name] Display detailed information on one or more volumes
docker volume rm [volume-name] Remove one or more volumes

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages