I. Concepts

Coming soon…

II. Setup

Follow this official guide from Docker Inc.

III. Containers

  • Manage containers:
    • Show syntax and all available COMMAND : docker container --help
    • Show meaning and all available options of a COMMAND: docker container COMMAND --help
      • Example:
        • docker container exec --help
        • docker container run --help
  • Common commands:
    • docker container ls [OPTIONS] : List containers.
      • e.g: docker container ls -a
    • docker container run [OPTIONS] IMAGE [COMMAND] [ARG…] : Run a command in a new container.
      • e.g: docker container run -it ubuntu-container
    • docker container start [OPTIONS] CONTAINER [CONTAINER…] : Start one or more stopped containers.
      • e.g: docker container start -ai ubuntu_container
    • docker container exec [OPTIONS] CONTAINER COMMAND [ARG…] : Run a command in a running container
      • e.g: docker container exec -it ubuntu_container bash
    • docker container top CONTAINER [ps OPTIONS]: Display the running processes of a container.
    • docker container inspect [OPTIONS] CONTAINER [CONTAINER…] : Display detailed information on one or more containers
      • e.g: docker container inspect ubuntu_container
    • docker container stats [CONTAINER...] : Display a live stream of container(s) resource usage statistics
      • e.g: docker container stats
    • docker container rm [OPTIONS] CONTAINER [CONTAINER…] : Remove one or more containers

IV. Images

  • Manage images:
    • Show syntax and all available COMMAND: docker image --help
    • Show meaning and all available options of a COMMAND: docker image COMMAND --help
      • Example:
      • docker image pull --help
      • docker image tag --help
  • Common commands:
    • docker image tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] : Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE.
    • docker image pull [OPTIONS] NAME[:TAG|@DIGEST] : Pull an image or a repository from a registry
  • Building Image: Build an image from a Dockerfile docker build [OPTIONS] PATH | URL | -
  • Dockerfile: INSTRUCTION arguments
    • ARG: is the only instruction that may precede FROM in the Dockerfile
      • Form: ARG <name>[=<default value>]
      • e.g: ARG VERSION=latest
        FROM busybox:$VERSION
    • FROM: initializes a new build stage and sets the Base Image for subsequent instructions
      • Forms:
        • FROM <image> [AS <name>]
        • FROM <image>[:<tag>] [AS <name>]
        • FROM <image>[@<digest>] [AS <name>]
    • RUN: execute any commands in a new layer on top of the current image and commit the results
      • Forms:
        • RUN <command>
        • RUN ["executable", "param1", "param2"]
    • CMD: to provide defaults for an executing container. Only one last CMD will take effect in a Dockerfile
      • Forms:
        • CMD ["executable","param1","param2"]  (exec form, this is the preferred form)
        • CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
        • CMD command param1 param2 (shell form)
    • EXPOSE: informs Docker that the container listens on the specified network ports at runtime
      • Form: EXPOSE <port> [<port>/<protocol>...]
      • e.g: EXPOSE 80/tcp
        EXPOSE 80/udp
    • ENV: sets the environment variable <key> to the value <value>
      • Forms:
        • ENV <key> <value>
        • ENV <key>=<value> ...
    • WORKDIR: sets the working directory for any RUNCMDENTRYPOINTCOPY and ADD instructions that follow it in the Dockerfile
      • Form: WORKDIR /path/to/workdir
      • e.g: WORKDIR /a
        WORKDIR b
        WORKDIR c
        the final pwd will be: /a/b/c
    • ADD: copies new files, directories or remote file URLs from <src> and adds them to the filesystem of the image at the path <dest>
      • Forms:
        • ADD [--chown=<user>:<group>] <src>... <dest>
        • ADD [--chown=<user>:<group>] ["<src>",... "<dest>"] (this form is required for paths containing whitespace)
      • Notes:
        • Each <src> may contain wildcards
        • The <dest> is an absolute path, or a path relative to WORKDIR
    • COPY: copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>
      • Forms:
        • COPY [--chown=<user>:<group>] <src>... <dest>
        • COPY [--chown=<user>:<group>] ["<src>",... "<dest>"] (this form is required for paths containing whitespace)
      • Notes:
        • Each <src> may contain wildcards
        • The <dest> is an absolute path, or a path relative to WORKDIR
    • ENTRYPOINT: allows configuring a container that will run as an executable
      • Forms:
        • ENTRYPOINT ["executable", "param1", "param2"] (exec form, preferred)
        • ENTRYPOINT command param1 param2 (shell form)
    • VOLUME:
    • LABEL | … :

XX. Others

  • prune: commands to clean up images, volumes, build cache, and containers
    • docker image prune to clean up just “dangling” images
    • docker system prune will clean up everything
    • docker image prune -a which will remove all images you’re not using
    • docker system df to see space usage.

LEAVE A REPLY

Please enter your comment!
Please enter your name here