Sample downsample code

2023-01-20   ES  

Docker is an open source application container engine that allows developers to pack their applications and rely on a transplant container, and then publish them on any popular Linux machine to achieve virtualization. -Baidu Encyclopedia

docker structure is as follows

The core of
is to use LXC to achieve the function of similar virtual machines to use hardware resources more efficiently.
docker ispect docker_container_id


  1. Install docker
    This article is mainly for Mac installation, similar to Linux.
    1. Checking system version
      To install Docker Toolbox, you need OSX version> = 10.8 “mountain lion”, the viewing method isClick Apple icon in the upper left corner-> About this mac
      system version
      If the system does not meet the requirements, please update the system first.
    2. GetInstallation file
    3. Double -click to open the installation mirror, the installation wizard will display the list of program to be installed
      What will be installed
      Press the ‘Continue‘ to provide custom installation options. What programs do you choose to install:
      It is recommended to install all.
      ClickInstalland enter the password will start installation.
    4. Installation is completed
      Among them, Docker Quickstart Terminal is equivalent to entering the Docker’s shortcut through the terminal, eliminating the operation and other operations. KITEMATIC is the graphical interface of the docker, which can be used to download the image and directly use it from the Docker Hub. Below are command behavior interfaces

Basic operation

  1. Install Image
    sudo docker pull ubuntu:12.04
    sudo docker pull
    is downloaded from the default warehouse; but sometimes the official warehouse download is slow, you can use the following command to specify the warehouse:
    sudo docker pull
  2. docker run commonly used parameters

  • ‘-i’:Keep STDIN open even if not attached
  • ‘-t’: Allocate a PSEUDO-TTY allocated a console interaction with container

For interactive operations in the container, such as shell script. We must use -i -t to apply for a console and container for data interaction. But when interacting with the same container through the pipeline, you cannot use -t. For example, the following command
echo test | docker run -i busybox cat

  • ‘-d’ to run the container in the background mode (DETACHED MODE). The current terminal window is no longer monitored by the container.
  • --rm: The container will be deleted immediately after the container is terminated
  • ‘-a = []’. What streams are mounted (‘stdin’, ’sTDOUT’, ’STDERR’) when you do n’t bring this parameter
  • –name ’: Naming the container
    docker run –name wei -itd busybox
  • docker PS lists the docker container during operation
    • ’-A ‘lists all containers
    • ‘q” lists the container ID of all processes,
    • Function: For example, kill all processes
      docker kill $(docker ps -q)
  • docker mirror
    1. Modify existing mirror
    2. Use the downloaded mirror to start the container first
      sudo docker run -it training/sinatra /bin/bash
      Remember easy ID, add JSON and GEM applications to containers
      [email protected]:/#: gem install json
      Use EXIT to exit the updated copy after exiting
      sudo docker commit -m “Add json gem” -a “Docker Newbee” 0b2616b0e5a8 ouruser/sinatra:test
      ‘-m’ parameter description information, ’-A’ specify the updated user information, and then the container ID used to create a mirror image. Finally, the target mirror warehouse name and TAG information are specified.
    3. Use dockerfile to create a mirror image
    4. New directory and dockerfile
      $ touch Dockerfile
    5. Dockerfile Each specified to create a mirroring layer,up to 127 layers
      # This is a comment
      FROM ubuntu:14.04
      MAINTAINER Docker Newbee [email protected]# Author
      RUN apt-get -qq update
      RUN apt-get -qqy install ruby ruby-dev
      RUN gem intall sinatra
      # put my local web site in myApp folder to /var/www
      ADD myApp /var/WWW
      # expose httpd port
      EXPOSE 80
      # the command to run
      CMD [“/usr/sbin/appachectl”, “-D”, “FOREGROUND”]
    6. Build generated mirror image
      sudo docker build -t=”ouruser/sinatra:v2”
      ‘-t’ s mark add tag, specify the new mirror user information
    7. Use a new mirror to start the container
      sudo docker run -it ouruser/sinatra:v2 /bin/bash
      docker tag 5db5f8471261 ouruser/sinatra:devel
      Change the mirror label
    8. Upload mirror image
      sudo docker push ouruser/sinatra
    9. Store and load
    10. sudo docker save -o ubuntu_14.04.tar ubuntu:14.04
    11. load
      sudo docker load –input ubuntu_14.04.tar
      sudo docker load < ubuntu_14.04.tar
    12. Remove
      docker rmi training/sinatra
      Note:Before deleting the image, you should firstdocker rmAll containers depend on the image
  • docker container
    1. New and startup: Docker Run
      sudo docker run -it ubuntu:14.04 /bin/bash
      Start a bash terminal to allow users to interact
    2. Started procedures for termination: Docker Start
    3. Guardian State Operation: ’-D’
      Obtain the output information of the container:
      sudo docker logs insane_babbage
      Enter the guardian container:
      docker attach container_name
    4. Termination container:
      docker stop container_name
      Restart the container:
      docker start container_name
      Restart container:
      docker restart container_name
      The operating container will be terminated and then restarted
    5. Export and import container
      • Export container snapshot to local:
        docker export container_id > container_name.tar
      • import container from local express photos:
        docker import container_path example/imagerepo
    6. Delete container
      docker rm container_id
      Delete the front container needs to stop
  • Docker Hub
    1. Login:
      docker login
      After entering the user name and password, the authentication information is stored in the local user directory.dockercfgFile
    2. Basic operation
      • search mirror:
        docker search centos
      • download mirror
        docker pull centos
      • Upload mirror image
        docker push image_name
      • automatic creation strategy
    3. Private warehouse
  • docker data management

    1. two ways:

    • data volume (data volumes)
    • Data Volumes Container
  • data volume

  • Features
    • Data volume can be shared between containers
    • The modification of the data volume will take effect immediately
    • The update of the data volume will not affect the mirror


    • volume will always exist until there is no container to use it
  • Create data volume
    Use whendocker runcommand-vParameters create and mount the data volume into the container. You can use multiple data volumes multiple times in a RUN
    docker run -d -P –name web -v /webapp training/webapp python
    Note:can be used in dockerfileVOLUMEAdd one or more new rolls to the container created by the mirror.
  • Mount a host directory to the container
    docker run -d -P –name web -v /src/webapp:/opt/webapp python
    will be the host/src/webappDirectory Mount it to the container/opt/wepapp
    Last add:roMount it to read only
    DockerfileDo not support this usage
  • Mount a host file to the container
  • Data volume container

    If there are some continuous updated data that needs to be shared between the containers, it is best to create a data volume container. The data volume container is a container for providing data volume for other containers.

  • Creation:
    docker run -d -v /dbdata –name dbdata training/postgres echo Data-only Container
    # 11
    docker run -d –volumes-from dbdata –name db1 training/postgres
  • Delete
    If the container (DBDATA, DB1) that is mounted will not be automatically deleted, you need to delete the last one that is still hung on itdocker rm -v
  • Backup
    docker run –volumes-from dbdata -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar …
  • recovery
    # Create a container dbdata2 with a data volume
    docker run -v /dbdata –name dbdata2 ubuntu /bin/bash
    # Create another container, mount DBDATA2 container, and use Untar to decompress the backup file to the container volume loaded
    docker run –volumes-from dbdata2 -v $(pwd):/backup busybox tar xvf /backup/backup.tar
  • docker network management
    1. external access container
      Specify port mapping through -P or -P parameters
      • -P: Randomly map a network port of 49000-49900 to the interior container open
      • -p: Specify the port, support format withip:hostPort:containerPort|ip::containerPort|hostPort:containerPortalso use UDP mark to specify UDP ports-p
      • Usedocker portto view the port configuration of the current mapping
        docker port nostalgic_morse 5000

    2. container interconnection
      # Create a database container
      docker run -d –name db training /postgres
      # 1
      docker run -d -P –name web –link db:db training/webapp python
      Sug container DB and web containers to establish an interconnection relationship,--linkFormat:--link name:alias, nameis the name of the container to be linked. Alias is the alias of this link. The connected container can bedocker ps
      • View connection information
      • Environment variable
        docker run –rm –name web2 –link db:db training /webapp env
        get environmental variables


        prefix uses an upper -writing connection alias
      • Father container web2/etc/hoistsFile
        docker run -it –rm –link db:db training/webapp /bin/bash
        # cat /etc/hosts aed84ee21bde db
        Here are two hosts. The first is the web container. The web container uses ID as its host name. The second is the IP and host name of the DB dbto test the connection status of Web2 and DB containers
  • Advanced network configuration
    1. network structure
    2. Configuration DNS
      Docker By mounting 3 related configuration files to the new container to make the host host DNS update all the container DNS passes/etc/resolv.confFile is immediately updated
      • -h HOSTNAME | --hostname=HOSTNAMEThe host name of the specified container will be written to the container/etc/hostsand/etc/hostname
      • --link=CONTAINER_NAME:ALIAS: Add a host name of another container

        In/etc/hosts, the process of allowing the new container can be connected to it with the host name Alias

      • dns=IP_ADDRESS: Let the container analyze not there/etc/hostshost name
      • dns-search=DOMAIN: Set the search domain of the container
    3. container access external network
      container access to the external network requires local forwarding support, through
      sysctl net.ipv4.ip_forward(Mac: sysctl net.inet.ip.forwarding)
      View whether there is any turnover forwarding, 1 is to open 0 to close, open through the following command
      sysctl -w net.ipv4.ip_forward=1(Mac:sysctl net.inet.ip.forwarding=1)


Related Posts

SQLDIAG-Configuration File-Extension

China Adult Blood Liposuction Guide (2016 revised edition) -The learning notes

hexo+github build a personal blog (super detailed tutorial)

Android adds bitmap to the overlay of View

Sample downsample code

Random Posts

nlp | Natural language processing -grammar analysis


MATLAB implements the variable threshold processing of the image segmentation block, and uses the OTSU method for dual value

Java Written year and month to query the calendar class