Docker study notes - container operations

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_43707160/article/details/99569089

ps: a vessel or a set of applications operate independently, and the operation-environment

Start container

  • Two ways to start a: based images and start a new container; two: Restart the container state to be terminated
  1. Create and start
    1. The main command docker run
      Here Insert Picture Description
    1. Start a bash terminal
      Here Insert Picture Description
      ps: -t option lets docker allocate a pseudo-terminal and bind to the standard input container, -i so that the container remains open standard input
  1. When the container is created using the docker run, standard practice in the background docker comprising:
  • Check whether there are specific local mirror, does not exist in the public warehouse download
  • Use a mirror to create and launch container
  • Assign a file system, and a mirror mounted on the outside layer of the read-only and writable layer
  • Host bridge configuration from the host bridge interface to a virtual interface to the container
  • Configuring an ip address from the address pool container
  • Execution of the application specified by the user
  • After completion of the implementation of the container is terminated

Start container has been terminated

  1. Available docker container start command has terminated directly to a container up and running
  2. The core container is performed by the application, the required resources are necessary to run the application

Background process

  1. By -d parameter lets docker run in the background, not the execution result output on the host. The output can be used to view docker logs, start using the -d parameter returns a unique ID
    Here Insert Picture Description

  2. docker container ls to view container information
    Here Insert Picture Description
    Here Insert Picture Description

Termination container

  1. docker container stopTerminate the operation of the vessel
    Here Insert Picture Description

  2. docker container ls -aView the final state of the container
    Here Insert Picture Description

Into the container

  1. Can be used docker attach or docker exec (recommended) command into the container

  2. attach command
    daemon process started
    Here Insert Picture Descriptionlisting all containers
    Here Insert Picture Description
    entering the vessel
    Here Insert Picture Description
    PS: If this current from the container exit, it will cause the container to stop

  3. exec command

    docker  exec -it {container id} bash 
    

    ps: When the exit from the container, the container does not cause to stop

Export and import container

  1. Export container , the container can be to a local snapshotdocker export {container ID} > export_name.tar
  2. Introducing snapshot of the container , the container can be introduced from the local snapshot to the mirror cat {快照文件} docker import - test/{镜像名}:{tag}
    may be introduced by its URL,docker import {URL}
  3. Docker load may be used to import image files stored in the local image library may be used to import a docker import container to the local snapshot image library. The difference is that the container will discard all snapshot files and metadata history information image file is stored intact record a larger volume. Introducing labels can reassign metadata information snapshot files from the container

Delete container

  1. Use docker container rm {容器}delete one stop state of the container
  2. For delete container running, you can add -f parameter
  3. Clean up all the container is terminated state:docker container prune

Guess you like

Origin blog.csdn.net/weixin_43707160/article/details/99569089