Basic use of Docker containers (i)

Source: Internet
Author: User
Tags docker ps docker run

Environment:

Host: physical machine equipped with centos7.2 I p:192.168.122.1 shutdown firewall selinux status is disabled

Software:docker-engine-1.10.3-1.el7.centos.x86_64.rpm

docker-engine-selinux-1.10.3-1.el7.centos.noarch.rpm

Operation:

Install the software yum install docker-engine-1.10.3-1.el7.centos.x86_64.rpm

docker-engine-selinux-1.10.3-1.el7.centos.noarch.rpm

Start systemctl start Docker

View Docker information Docker version

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/85/E4/wKiom1etfpDQkY3WAABNSevj3VU503.png "style=" float: none; "title=" Picture1.png "alt=" Wkiom1etfpdqky3waabnsevj3vu503.png "/>

Import docker image Docker load-i Centos.tar

View Docker image Docker images

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/85/E3/wKioL1etfpCjOzSfAABELq15zek900.png "style=" float: none; "title=" Picture2.png "alt=" Wkiol1etfpcjozsfaabelq15zek900.png "/>

Running the container

1> Docker run-it--name test RHEL7 bash Interactive run in foreground bash

##### opens the container and enters the interactive interface:ctrl+d closes the container directly and exits the interactive interface ctrl+p+q exit the interactive interface without closing the container

2> Docker run-d--name test1 nginx-d means running in the background

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/85/E3/wKioL1etfpHjJywgAABPd131zJA321.png "style=" float: none; "title=" Picture3.png "alt=" Wkiol1etfphjjywgaabpd131zja321.png "/>

3> Docker run-d--name nginx-v index.html:/usr/share/ngin/html/index.html-p 8080:80 nginx Create container -v mount the local index.html file to the container - p Port map maps the container's ports to the physical machine's 8080

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/85/E4/wKiom1etfpHjRliRAAASLrVKTWg489.png "style=" float: none; "title=" Picture4.png "alt=" Wkiom1etfphjrliraaaslrvktwg489.png "/>

You can access the container 's Nginx by accessing the 8080 Port of the physical machine or the IP of the container

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/85/E3/wKioL1etfpHS8J0_AACYzPOfKjE896.png "style=" float: none; "title=" Picture5.png "alt=" Wkiol1etfphs8j0_aacyzpofkje896.png "/>

4> Docker Create--name file-v/tmp/data1:/data1-v/tmp/data2:/data2 Ubuntu Bash Add volume container volume container can be called on a new container to make a volume Same mount of container

5> Docker run--rm--volumes-from file-v/tmp/backup:/backup ubuntu tar cf/backup/back.tar data1 creates a container that Row data1 package to /backup/ Delete container --volumes-from call file The container is mounted so that the new container also has the same Mount

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/E4/wKiom1etfpHhZsXpAAAwmPXFXYk931.png "style=" float: none; "title=" Picture6.png "alt=" Wkiom1etfphhzsxpaaawmpxfxyk931.png "/>

6> Docker run-it--name Ubuntu--net host Ubuntu Bash runs a container --net indicates that the specified container uses the network as host Such a container will use the same network information as the physical machine to open the same network port but there will be a scramble for resources

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/85/E4/wKioL1etfpKDgvilAACDsVWlpms303.png "style=" float: none; "title=" Picture7.png "alt=" Wkiol1etfpkdgvilaacdsvwlpms303.png "/>

7> Docker run-it--name vm1--net none Ubuntu bash runs a container, network information is empty convenient custom configuration

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/85/E4/wKiom1etfpLzG1W9AABbWl6Immg816.png "style=" float: none; "title=" Picture8.png "alt=" Wkiom1etfplzg1w9aabbwl6immg816.png "/>

The network configuration for the container vm1 is as follows:

IP link Add name veth0 type Veth Peer name veth1 Create container virtual network interface

Brctl addif Docker0 Veth0 will be a section to the local Docker0 on

IP link set Dev veth0 up

IP link set dev veth1 up interface End status

Docker Inspect-f ' {. State.pid}} ' vm1 filters out the container vm1 Pid is 5794

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/E4/wKioL1etfpKx5_nvAADPXhOGyVU704.png "style=" float: none; "title=" Picture9.png "alt=" Wkiol1etfpkx5_nvaadpxhogyvu704.png "/>

IP netns Add test Add a network namespace Test

IP netns list viewing lists

Ln-s/proc/5794/ns/net/var/run/netns/5794 do soft connection

IP link Set veth1 netns 5794 add the virtual NIC interface veth1 to the 5794

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/85/E4/wKiom1etfpORCYtmAAAzOFkggQc164.png "style=" float: none; "title=" Picture10.png "alt=" Wkiom1etfporcytmaaazofkggqc164.png "/>

In the container through the IP addr Show you can see that a device has been added veth1

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/85/E4/wKioL1etfpOR7x0NAADNoAi4zio575.png "style=" float: none; "title=" Picture11.png "alt=" Wkiol1etfpor7x0naadnoai4zio575.png "/>

IP netns exec 5794 IP addr add 172.17.0.10/24 dev veth1 set container on physical machine VM1 network address is 172.17.0.10/24

IP netns exec 5794 IP link set veth1 up enable device veth1

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/E4/wKiom1etfpOxMja9AAA-g_O5RiU622.png "style=" float: none; "title=" Picture12.png "alt=" Wkiom1etfpoxmja9aaa-g_o5riu622.png "/>

View in Container

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/85/E4/wKioL1etfpSQNTIFAACdR0xaboA974.png "style=" float: none; "title=" Picture13.png "alt=" Wkiol1etfpsqntifaacdr0xaboa974.png "/>

Container IP settings succeeded


Docker common Operations:

Docker PS View the currently running container

Docker ps-a View all containers (including containers for running)

Docker ps-q View container ID

Docker Stop/start test Close or open container test Here you can use either the container name or the container ID .

Docker logs Test View container's logs

Docker attach test into container

Docker RM Test Delete Container

Docker stop ' Docker Ps-aq ' stops all containers

Docker RM ' Docker Ps-aq ' removes all container containers before removing it needs to stop first


This article is from the "11889934" blog, please be sure to keep this source http://11899934.blog.51cto.com/11889934/1837333

Basic use of Docker containers (i)

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.