Docker安裝使用

  • Docker版本及依賴的基礎環境

    Docker版本

        雙發行版

            docker-ee

            docker-ce

                moby

    依賴的基礎環境

        64 bits CPU

        Linux Kernel 3.10+

        Linux Kernel cgroups and namespaces

  • Docker安裝方法

    1、CentOS Extras Repo

    2、Docker-CE 

        下載:https://download.docker.com/

        倉庫配置文件:https://download.docker.com/linux/centos/docker-ce.repo

  • Docker程序環境

    環境配置文件:

            /etc/sysconfig/docker-network

            /etc/sysconfig/docker-storage

            /etc/sysconfig/docker

    Unit File:

            /usr/lib/systemd/system/docker.service

    Docker Registry配置文件:

            /etc/containers/registries.conf

    docker-ce:

            配置文件:/etc/docker/daemon.json

    Docker鏡像加速

        Docker cn            

            {

                "registry-mirrors": ["https://registry.docker-cn.com"]

            }

        中國科技大學

        阿里雲加速器            

            註冊阿里雲賬號,專用加速器地址獲得路徑:

                https://cr.console.aliyun.com/#/accelerator

  • Docker使用

    啓動服務即可使用Docker

    systemctl start docker

    Docker命令

    Usage:  docker [OPTIONS] COMMAND

    A self-sufficient runtime for containers
    
    Options:
          --config string      Location of client config files (default "/root/.docker")
      -D, --debug              Enable debug mode
      -H, --host list          Daemon socket(s) to connect to
      -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")
                               (default "info")
          --tls                Use TLS; implied by --tlsverify
          --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")
          --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
          --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
          --tlsverify          Use TLS and verify the remote
      -v, --version            Print version information and quit
    Management Commands:    
          config      Manage Docker configs
          container   Manage containers
          image       Manage images
          network     Manage networks
          node        Manage Swarm nodes
          plugin      Manage plugins
          secret      Manage Docker secrets
          service     Manage services
          stack       Manage Docker stacks
          swarm       Manage Swarm
          system      Manage Docker
          trust       Manage trust on Docker images
          volume      Manage volumes
    Commands:    
          attach      Attach local standard input, output, and error streams to a running container
          build       Build an image from a Dockerfile
          commit      Create a new image from a container's changes
          cp          Copy files/folders between a container and the local filesystem
          create      Create a new container
          diff        Inspect changes to files or directories on a container's filesystem
          events      Get real time events from the server
          exec        Run a command in a running container
          export      Export a container's filesystem as a tar archive
          history     Show the history of an image
          images      List images
          import      Import the contents from a tarball to create a filesystem image
          info        Display system-wide information
          inspect     Return low-level information on Docker objects
          kill        Kill one or more running containers
          load        Load an image from a tar archive or STDIN
          login       Log in to a Docker registry
          logout      Log out from a Docker registry
          logs        Fetch the logs of a container
          pause       Pause all processes within one or more containers
          port        List port mappings or a specific mapping for the container
          ps          List containers
          pull        Pull an image or a repository from a registry
          push        Push an image or a repository to a registry
          rename      Rename a container
          restart     Restart one or more containers
          rm          Remove one or more containers
          rmi         Remove one or more images
          run         Run a command in a new container
          save        Save one or more images to a tar archive (streamed to STDOUT by default)
          search      Search the Docker Hub for images
          start       Start one or more stopped containers
          stats       Display a live stream of container(s) resource usage statistics
          stop        Stop one or more running containers
          tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
          top         Display the running processes of a container
          unpause     Unpause all processes within one or more containers
          update      Update configuration of one or more containers
          version     Show the Docker version information
          wait        Block until one or more containers stop, then print their exit codes
        
        Run 'docker COMMAND --help' for more information on a command.

    常用操作

查看docker相關的信息:
		version
		info
	鏡像:
		images
		rmi
		pull
	容器:
		run:創建並運行一個容器;
		create:創建一個容器;
		start:啓動一個處於停止狀態容器;
		創建:
			create
			run 
		啓動:
			start			
		停止:
			kill
			stop			
		重啓:
			restart			
		暫停和繼續:
			pause
			unpause 			
		刪除容器:
			rm
			run --rm
創建容器:
		基於“鏡像文件”,
			鏡像文件有默認要運行的程序;
				
		注意:
			運行的容器內部必須有一個工作前臺的運行的進程;
			docker的容器的通常也是僅爲運行一個程序;
				要想在容器內運行多個程序,一般需要提供一個管控程序,例如supervised。
				
		run, create
			--name CT_NAME
			--rm:容器運行終止即自行刪除
			--network BRIDGE:讓容器加入的網絡;
				默認爲docker0;
			
			交互式啓動一個容器:
				-i:--interactive,交互式;
				-t:Allocate a pseudo-TTY
				
				從終端拆除:ctrl+p, ctrl+q
				
		attach:附加至某運行狀態的容器的終端設備;
			
		exec:讓運行中的容器運行一個額外的程序;
		
		查看:
			logs:Fetch the logs of a container,容器內部程序運行時輸出到終端的信息;
			
			ps:List containers
				-a, --all:列出所有容器;
				--filter, -f:過濾器條件顯示
					name=
					status={stopped|running|paused}
					
			stats:動態方式顯示容器的資源佔用狀態:
				
			top:Display the running processes of a container

    容器狀態及命令

        image.png

    

    容器的狀態:

        created

        runing

paused

stopped

deleted

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章