Docker Installation and QuickStart (MAC)

Source: Internet
Author: User
Tags terminates docker ps docker hub docker toolbox

Docker is an open-source application container engine that allows developers to package their applications and dependencies into a portable container, and then publish them to any popular Linux machine or virtualize them. – Baidu Encyclopedia

The Docker structure is as follows

The core is the use of LXC to implement virtual machine-like capabilities to make more efficient use of hardware resources.
Docker Ispect docker_container_id

Installation
    1. Installing Docker
      This article is primarily for Mac installations, like Windows and Linux.
      1. Check the system version
        To install Docker Toolbox requires OSX version >=10.8 "Mountain Lion", the View method is 点击左上角苹果图标->About this Mac

        If the system does not meet the requirements, please update the system first.
      2. Get installation files
      3. Double-click to open the installation image and the Installation Wizard will display a list of the programs that will be installed

        After pressing ' Continue ', a Custom installation option will be provided and you can choose which programs to install:

        It is recommended to install all.
        Tapping Install and entering a password will start the installation.
      4. Installation Complete

        The Docker Quickstart terminal is the equivalent of a shortcut to Docker through the terminal, eliminating the hassle of logging in, Kitematic is the graphical interface of Docker, which can be visualized and used directly from the Docker hub. The following are the command-behavior interfaces
Basic operations


    1. Install image
      sudo docker pull ubuntu:12.04
      Equivalent to
      sudo docker pull registery.hub.docker.com/ubuntu:12.04
      It is downloaded from the default repository, but sometimes the official warehouse download is slow, and you can specify the warehouse using the following command:
      sudo docker pull dl.dockerpool.com:5000/ubuntu:12.04
    2. Docker Run common parameters

    • '-I ': Keep STDIN Open even if not attached
    • '-T ': Allocate a Pseudo-tty assigns a console to interact with the container

For interactive operations within the execution container, such as shell scripts. We must use-I-T to request a console to interact with the container for data. However, you cannot use-t when interacting with a container through a pipeline. For example, the following command
echo Test | Docker Run-i BusyBox Cat

  • '-d ' enables the container to run in background mode (detached modes) and the current terminal window is no longer monitored by the container and can be re-mounted using Docker attach
  • --rm: The container is deleted immediately after it terminates
  • '-a=[] ' specifies which streams the container mounts (' STDIN ', ' STDOUT ', ' STDERR ') are all mounted without this parameter
  • ' –name ': Name the container
    Docker Run–name WEI-ITD BusyBox
  • Docker PS Lists the running Docker containers
    • '-a ' lists all containers
    • '-Q ' lists the container IDs of all processes,
    • Action: such as killing all processes
      Docker kill $ (Docker ps-q)
  • Docker image
    1. Modify an existing mirror
    2. Start the container with the downloaded image first
      sudo docker run-it Training/sinatra/bin/bash
      Remember easy IDs, add JSON and gems to the container two apps
      [Email protected]:/#: Gem install JSON
      Submit an updated copy after exiting with exit
      sudo docker commit-m "Add json gem"-a "Docker Newbee" 0b2616b0e5a8 ouruser/sinatra:test
      '-m ' parameter description information, '-a ' specifies the updated user information, followed by the container ID used to create the image, finally specifying the target image warehouse name and tag information, and then returning the ID of the mirror after creation
    3. Creating a mirror using Dockerfile
    4. New Catalog and Dockerfile
      mk d IR sINaT R a CD Sinatra
      $ Touch Dockerfile
    5. Dockerfile each of the specified layers creates a layer of mirroring, 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 image
      sudo docker build-t= "Ouruser/sinatra:v2"
      The '-t ' tag adds tag, specifying the user information for the new mirror
    7. Start the container with a new mirror
      sudo docker run-it Ouruser/sinatra:v2/bin/bash
      Docker tag 5db5f8471261 Ouruser/sinatra:devel
      Change Mirror Label
    8. Upload image
      sudo docker push Ouruser/sinatra
    9. Deposit out and load
    10. Deposit out
      sudo docker save-o Ubuntu_14.04.tar ubuntu:14.04
    11. Gta5-In
      sudo docker load–input Ubuntu_14.04.tar
      Or
      sudo docker load < Ubuntu_14.04.tar
    12. Removed from
      Docker RMI Training/sinatra
      Note: You should first docker rm drop all containers that depend on the image before removing it
  • Docker container
    1. New and started: Docker run
      sudo docker run-it Ubuntu:14.04/bin/bash
      Launch a bash terminal that allows users to interact
    2. Start terminated program: Docker start
    3. Daemon operation: '-d '
      Gets the output information of the container:
      sudo docker logs Insane_babbage
      Enter the daemon container:
      Docker Attach Container_name
    4. To terminate a container:
      Docker Stop Container_name
      To restart the container:
      Docker start Container_name
      To restart the container:
      Docker Restart Container_name
      Terminates the running state container and restarts it.
    5. Exporting and Importing containers
      • Export container snapshot to Local:
        Docker Export container_id > Container_name.tar
      • To import a container from a local snapshot:
        Docker Import Container_path Example/imagerepo
    6. Delete Container
      Docker RM container_id
      Container to be stopped before deletion
  • Docker Hub
    1. Login:
      Docker Login
      After entering the user name and password, the authentication information is saved in the file of the local user directory. .dockercfg
    2. Basic operations
      • Search Image:
        Docker Search CentOS
      • Download image
        Docker Pull CentOS
      • Upload image
        Docker Push Image_name
      • Automatically create slightly
    3. Private Warehouse
      Slightly
  • Docker Data Management

    1. Two different ways:

    • Data Volume (Volumes)
    • Data volume container (Volumes container)
  • Data volumes

  • Characteristics
    • Data volumes can be shared between containers
    • Changes to the data volume will take effect immediately
    • Updates to a data volume do not affect mirroring
    • The volume will persist until no container uses it
  • Create a data volume
    docker runuse -v parameters to create and mount data volumes into the container when using commands. Can be used multiple times to mount multiple data volumes in one run
    Docker run-d-p–name web-v/webapp training/webapp python app.py
    Note: You can use it in Dockerfile VOLUME to add one or more new volumes to the container created by the image.
  • Mount a host directory to a container
    Docker run-d-p–name web-v/src/webapp:/opt/webapp python app.py
    Mount the directory of the host to the container. /src/webapp /opt/wepapp
    Last plus :ro mount as read-only
    Dockerfile does not support this usage
  • Mount a host file to the container
    Slightly
  • Data Volume container

    If there are some continuously updated data that need to be shared between containers, it is a good idea to create a data volume container that is used specifically to provide data volumes for use by other containers.

  • Create:
    Docker run-d-v/dbdata–name dbdata training/postgres echo data-only Container
    #挂载
    Docker Run-d–volumes-from Dbdata–name db1 training/postgres
  • Delete
    If you delete a mounted container (dbdata, DB1) The data volume will not be deleted automatically, you need to delete the last one that is still hanging in its container.docker rm -v
  • Backup
    Docker Run–volumes-from Dbdata-v $ (PWD):/backup Ubuntu tar Cvf/backup/backup.tar ...
  • Recovery
    # Create a container with a data volume dbdata2
    Docker run-v/dbdata–name Dbdata2 Ubuntu/bin/bash
    # Create another container, mount the DBDATA2 container, and use Untar to extract the backup file to the mounted container volume
    Docker Run–volumes-from Dbdata2-v $ (PWD):/backup busybox tar Xvf/backup/backup.tar
  • Network Management in Docker
    1. External Access Container
      Specifying port mappings with the-p or-p parameters
      • -P: Randomly maps a 49000-49900 port to an internal container open network port
      • -p: Specify ports, supported formats, ip:hostPort:containerPort|ip::containerPort|hostPort:containerPort and UDP tags can also be used to specify UDP ports-p 127.0.0.1:5000:5000/udp
      • Use docker port to view the currently mapped port configuration
        Docker Port Nostalgic_morse 5000

        127.0.0.1:49155

    2. Container interconnect
      #创建数据库容器
      Docker run-d–name db training/postgres
      # interconnect
      Docker run-d-p–name web–link db:d b training/webapp python app.py
      Such container db and Web container establish interconnection, --link format: --link name:alias , Names is the name of the container to be linked to, alias is the alias of the link, and the connected container can be viewed in Docker PS
      • View connection Information
      • environment Variables
        Dock Er run–rm–name web2–link db:db training/webapp env
        Get environment variable
        ...
        db_name=/web2/db
        db_port=tcp://172.17.0.5:5432
        db_port_5000_tcp=tcp://172.17.0.5:5432
        ...
        prefix with uppercase connection aliases
      • parent Container web2 /etc/hoists file
        Docker run-it–rm–link db:db training/webapp/bin/bash
        # cat/etc/hosts
        172.17.0.7 Aed84ee21bde
        ...
        172.17.0.5 DB
        There are two hosts, the first is the Web container, the Web container uses the ID as its host name, the second is the IP and hostname of the DB container, and you can use Ping db To test the connection status of the WEB2 and DB containers
  • Advanced network Configuration
    1. Network structure
    2. Configure DNS
      Docker updates all container DNS files immediately after a host host DNS update by mounting 3 related profiles to the new container /etc/resolv.conf
      • -h HOSTNAME | --hostname=HOSTNAMESpecifies the host name of the container that will be written to /etc/hosts and from the container. /etc/hostname
      • --link=CONTAINER_NAME:ALIAS: Add a host name for another container to /etc/hosts , so that the process of the new container can use the hostname alias to connect to it
      • dns=IP_ADDRESS: Let the container resolve /etc/hosts the host name that is not in
      • dns-search=DOMAIN: Sets the search domain for the container
    3. Container access to external network
      Container access to the external network requires local forwarding support, through
      Sysctl Net.ipv4.ip_forward (Mac:sysctl net.inet.ip.forwarding)
      Check that there is no turn on forwarding, 1 is on 0 for off, open by the following command
      Sysctl-w net.ipv4.ip_forward=1 (Mac:sysctl net.inet.ip.forwarding=1)
  • Docker Installation and QuickStart (MAC)

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.