Docker necessary command

Source: https: //macrozheng.github.io/mall-learning/#/reference/docker

Developers must-Docker command

This article explains the installation and use of the environment Docker Docker commonly used commands, a great help to master these applications have to be deployed under Docker environment.

Docker Profile

Docker is an open source application container engine that lets developers can package their applications and dependencies into a portable mirror, and then publish to any of the popular Linux or Windows machine. Docker can be more convenient to use low packaging, testing, and deploying applications.

Docker installation environment

  • Install yum-utils:
    yum install -y yum-utils device-mapper-persistent-data lvm2
  • Add docker warehouse location yum source:
    yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  • Installation docker:
    yum install docker-ce
  • Start docker:
    systemctl start docker

Docker mirror commonly used commands

Search Mirror

docker search java

Show pictures

Download image

docker pull java:8

How to find the version supported by the mirror

Since docker search command can only find out whether there is the mirror, the mirror can not find a supported version, so we need to search for the version supported by docker hub.

  • Docker hub into the official website address: https: //hub.docker.com

  • Then search image needs: Show pictures

  • View mirror supported versions: Show pictures

  • Mirroring the download operation:

    docker pull nginx:1.17.0

Listed Mirror

docker images

Show pictures

Remove Mirror

  • Specify the name to remove the mirror
    docker rmi java:8
  • Specify the name remove the mirror (mandatory)
    docker rmi -f java:8
  • Forced to delete all mirrors
    docker rmi -f $(docker images)

Docker containers commonly used commands

New and launch container

docker run -p 80:80 --name nginx -d nginx:1.17.0
  • -d option: that run in the background
  • --name option: After you specify the name of the vessel is running nginx, after the vessel can be operated by name
  • -p option: Specifies the port mapping format: hostPort: containerPort

Listed container

  • Listed container running:
    docker ps
    Show pictures
  • List all containers
    docker ps -a
    Show pictures

    Stop the container

    # $ContainerName及$ContainerId可以用docker ps命令查询出来
    docker stop $ContainerName(或者$ContainerId)
    such as:
    docker stop nginx
    #或者
    docker stop c5f5d5125587

    Forced to stop container

    docker kill $ContainerName(或者$ContainerId)

    Start a stopped container

    docker start $ContainerName(或者$ContainerId)

    Into the container

  • First check out the pid container:
    docker inspect --format "{{.State.Pid}}" $ContainerName(或者$ContainerId)
  • The containers enter the container pid:
    nsenter --target "$pid" --mount --uts --ipc --net --pid
    Show pictures

    Delete container

  • Removes the specified container:
    docker rm $ContainerName(或者$ContainerId)
  • Forced to remove all containers;
    docker rm -f $(docker ps -a -q)

    View log container

  • All your current log
    docker logs $ContainerName(或者$ContainerId)
  • Dynamic View Log
    docker logs $ContainerName(或者$ContainerId) -f
    Show pictures

    Check the IP address of the container

    docker inspect --format '{{ .NetworkSettings.IPAddress }}' $ContainerName(或者$ContainerId)
    Show pictures

    Time synchronization host to the vessel

    docker cp /etc/localtime $ContainerName(或者$ContainerId):/etc/

    View docker use in the host cpu, memory, network, io situation

  • Check the specified container situation:
    docker stats $ContainerName(或者$ContainerId)
    Show pictures
  • View all containers case:
    docker stats -a
    Show pictures

    Docker bash into the interior of the container

    docker exec -it $ContainerName /bin/bash
    Show pictures

Modifying the image storage location Docker

  • View Docker mirrored storage location:
    docker info | grep "Docker Root Dir"
    Show pictures
  • Close Docker Service:
    systemctl stop docker
  • Moved to the target directory path:
    mv /var/lib/docker /mydata/docker
  • Soft establish the connection:
    ln -s /mydata/docker /var/lib/docker
    Show picturesShow pictures

Guess you like

Origin www.cnblogs.com/ooo0/p/11484565.html