Docker - AshokBhat/notes GitHub Wiki

About

  • Most popular container software
  • Service has both free and premium tiers
  • Started in 2013 and is developed by Docker Inc

Common docker commands

Use-case Command
Build image docker build - < Dockerfile
Pull image docker pull ...
Run a command in a new container docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
List images docker images [OPTIONS] [REPOSITORY[:TAG]]
List containers docker container ls
Remove all stopped containers docker container prune [OPTIONS]

Dockerfile instructions

Instruction Description
ARG Define variables
FROM Specify base image for building a new image
LABEL Add metadata to an image, such as description, version, author...
RUN Command to execute during build process Each RUN instruction creates a new layer on top of the current image
ADD Copy files and directories
COPY Similar to ADD, only a local file or directory
ENV Define an environment variable.
CMD Specify a command that will be executed when you run a container You can use only one CMD instruction in your Dockerfile
ENTRYPOINT Defines what command will be executed when running a container
WORKDIR Sets the current working directory for the RUN, CMD, ENTRYPOINT, COPY, and ADD instructions
USER Set the username or UID to use for the RUN, CMD, ENTRYPOINT, COPY, and ADD instructions
VOLUME Mount a host machine directory to the container
EXPOSE Specify the port on which the container listens at runtime

How docker works

How docker works

Terminologies

Docker Engine

  • Software that hosts the containers

Container

  • Runtime instance of a docker image

Dockerfile

  • A text document that contains all the commands you would normally execute manually in order to build a Docker image.

Docker image

  • Basis of containers
  • An ordered collection of root filesystem changes and the corresponding execution parameters for use within a container runtime.
  • Typically contains a union of layered filesystems stacked on top of each other.
  • Does not have state and it never changes.

Layer

  • A modification to the image represented by an instruction in the Dockerfile

Tag

  • A label applied to a Docker image in a repository.

Repository

  • A set of Docker images
  • The different images in the repository can be labeled using tags.

Docker Hub

  • A centralized resource for working with Docker and its components

See Also