Docker image operation

  • Pull image docker pull

    Docker pull [Registry] / [Repository] / [Image] : [Tag].

    • By default, Docker will pull images from docker. IO. If you have your own image repository, you can replace Registry with your own Registry server.

    • Library is Docker’s default image Repository. Library is Docker’s default image Repository.

    • Image indicates the Image name.

    • Tag is the image Tag. If you do not specify the image Tag, the default value is latest.

    • Library is Docker’s default image Repository. Library is Docker’s default image Repository.

    • Image indicates the Image name.

    • Tag is the image Tag. If you do not specify the image Tag, the default value is latest.

  • Rename image docker tag

    docker tag [SOURCE_IMAGE][:tag] [TARGET_IMAGE][:tag]

  • View View the existing docker image ls/Docker images

  • Delete the useless image docker RMI

  • Build the mirror

    • The docker commit command commits from a running container to an image.
    • The docker build command builds an image from a Dockerfile.

Dockerfile instruction header
FROM The first line of a Dockerfile must be FROM, followed by the image name, which represents the base image on which we are building our container.
RUN RUN is followed by a specific command, similar to the Linux command line execution command.
ADD Copy local or remote files to the image
COPY Copy local files to the image
USER Specifies the user to start the container
ENTRYPOINT The start command for the container
CMD CMD provides default parameters for the ENTRYPOINT directive, or you can use CMD alone to specify container start parameters
ENV Specifies the container runtime environment variable in the form key=value
ARG Define external variables that can be passed as build-arg = when building the image
EXPOSE Specifies the port on which the container listens. The format is [port]/ TCP or [port]/udp
WORKDIR Set the working directory for all RUN, CMD, ENTRYPOINT, COPY, and ADD commands that follow in Dockerfile.

Docker container operations

  • The life cycle of the container

    1. Created: created initially

    2. Running: Indicates the running status

    3. Stopped: Indicates the stopped state

    4. Paused: paused

    5. Deleted: indicates a deletion

  • Container lifecycle operations

    • Docker create-it –name=busybox busybox

    • Docker start Starting status -> Running Status/Stopped Status -> Running Status

    • Docker stop Running status -> Stopped status

    • Docker Pause Running status -> Pause status

    • Docker unpause Pause status -> Running status

    • Docker rm to delete

    • Docker restart Restarts the image

    • Docker attach/Docker exec -it CONTAINER

    • Docker export busybox > busybox.tar Export busybox

    • Docker import busybox. Tar busybox:test imports containers

    • docker run [OPTIONS] IMAGE [COMMAND] [ARG…]

      • OPTIONS

        • -a stdin: specifies the standard input and output types. The options are stdin, STDOUT, or STDERR.

        • -d: Runs the container in the background and returns the container ID.

        • -i: Runs the container in interactive mode, usually with -t.

        • -p: indicates random port mapping. Ports inside a container are randomly mapped to ports on a host

        • -p: specifies the port mapping. The format is host (host) port: container port

        • -t: reassigns a pseudo-input terminal to the container. It is usually used together with -i.

        • –name=”nginx-lb”: specify a name for the container;

        • — DNS 8.8.8.8: Specifies the DNS server used by the container. The default DNS server is the same as the host server.

        • –dns-search example.com: specify the container DNS search domain name, which is the same as the host by default.

        • -h “Mars “: specifies the hostname of the container.

        • -e username=” Ritchie “: Set the environment variable.

        • –env-file=[]: reads environment variables from specified files;

        • –cpuset=”0-2″ or –cpuset=”0,1,2″: bind the container to the specified CPU;

        • -m: sets the maximum memory used by a container.

        • – net = “bridge” : specify the container’s network connection type, support bridge/host/none/container: four types;

        • –link=[]: Add link to another container;

        • –expose=[]: Open a port or group of ports;

        • –volume, -v: Binds a volume