docker-1.12 Run command and detailed parameters

Source: Internet
Author: User
Tags php and root directory docker ps docker run

http://blog.csdn.net/kunloz520/article/details/53839237

At the beginning of this article, we are going to get to the point where we officially start our Docker, and use it.

First, the first command we're going to introduce is also the most central command of Docker: Docker run

I'm going to dockerrun. Parameter one by one to explain to you, let us first understand what you need. (I'll make a list of the usual ones)

First look at the command format:[HTML] View plain copy Usage: docker run [options] image [command] [arg ...]           -d, --detach=false           Specifies whether the container runs in the foreground or in the background and defaults to false        -i, --interactive=false     open stdin for console interaction        -t, --tty=false              assign TTY devices, which can support terminal login, default to false        -u, --user= ""                Specify the container's users        -a, --attach=[]              login container (must be a container starting with docker run -d)      -w, --workdir = ""             Specify the working directory of the container       -c ,  --cpu-shares=0         Set Container CPU weight, use in CPU sharing scenario        -e, -- env=[]                Specify environment variables, This environment variable can be used in a container        -m, --memory= ""               Specify memory caps for containers        -P, --publish-all=false      specify ports exposed by the container        -p, --publish=[]             specify ports exposed by the container       -h, --hostname= ""             Specify the host name of the container        -v, -- volume=[]             mount a storage volume to a container, mount it to a directory in the container         --volumes-from=[]           Attach a volume on another container to a container and attach it to an item in the container.Records      --cap-add=[]                 Add permissions, permissions list See:http://linux.die.net/man/7/capabilities       -- cap-drop=[]               Delete permissions, The list of rights is described in:http://linux.die.net/man/7/capabilities       --cidfile= ""                  after running the container, write the container PID value in the specified file, a typical monitoring system usage        --cpuset= ""                   set which CPUs can be used by the container, this parameter can be used to container exclusive cpu       --device=[ ]                 Add the host device to the container, Equivalent to device direct        --dns=[]                     DNS server for the specified container        --dns-search=[]              Specify the DNS search domain name for the container, write to the container's/etc/resolv.conf file         --entrypoint= ""              Overwrite the entry point of image        --env-file=[]                Specify environment variable file, file format is one environment variable per line        --expose=[]                  specify the port exposed by the container, That is, modify the exposed port of the mirror        --link=[]                    Specify the association between containers, use other containers ' IP, env, and so on information         --lxc-conf=[]               Specifies the configuration file for the container, only when the--EXEC-DRIVER=LXC is specifiedUse        --name= ""                     Specify the container name and subsequent container management by name, and the links feature needs to use the name        --net= "Bridge"               container network settings :                                    bridge  Use the Docker daemon specified bridge                                           host    //container using the host's network                                       container:name_or_id  >//use the network of other containers, Share IP and Port network resources                                        none  containers use their own networks (similar to--net=bridge), but do not configure       --privileged=false           Specifies whether the container is a privileged container, and the privileged container has all capabilities       --restart= "No"               Specify the restart policy after the container stops:                                     No: Container exits without restarting                                        On-failure: Container failure exits (return value not 0) restart                                       always: Container exits always restarts        --rm=false                   Specifies that containers are automatically deleted after the container is stopped (does not support the docker  run -d start-up container)        --sig-proxy=true             settings are accepted and processed by the agent, but SIGCHLD, sigstop, and Sigkill cannot be proxied     



These are some of the more commonly used parameters of run.

So let's give some common examples.

Let's say we use:

centos6.8 (pure system, no execution of anything after startup),

Centos6.8-mysql (contains MySQL database),

CENTOS6.8-HTTPD (including PHP and Apache servers),

Three mirrors.

Case 1, run a simple container that needs to contain console management

[root@centos7.2 ~] #docker run-i-t centos6.8

Once this container executes, it goes to the default thread "/bin/bash" and goes directly to the console operation. When the control is exited, the container is terminated.

Case 2, run a container that executes in the background, and also manage [HTML] view plain copy [root@centos7.2 ~] #docker run-i-t-d centos6.8 with the console

Once this container executes, the default thread "/bin/bash" will be executed automatically, but will not allow you to enter the console operation immediately. will be executed in the background, using Docker PS to see the current running console. Entering the container uses Docker attach "Container name or id".

Case 3, run a container with commands in the background, do not directly display the container internal information [HTML] view plain copy [root@centos7.2 ~] #docker run-d centos6.8 Ping Www.doc Ker.com

This container will be permanently executed in the background because the ping thread will not stop. Unless you stop the ping thread.

Case 4, run a container running in the background, with commands, the program will be terminated after the restart to continue to run, but also with the console management [HTML] view plain copy [root@centos7.2 ~] #docker run-d-- Restart=always centos6.8 Ping www.docker.com

This container will be permanently executed in the background because the ping thread will not stop. If you terminate the ping thread, the container will reboot to continue the ping function

Case 5, we need to specify a name for the container [HTML] view plain copy [root@centos7.2 ~] #docker run-d--name=server-dbcentos6.8-mysql/usr/ Bin/mysql_safe-d

At this time our container name is SERVER-DB, while activating the database MySQL background thread, let it run constantly, and our container will not be closed.

Case 6, we need to make server-http container connection server-db container [HTML] view plain copy [root@centos7.2 ~] #docker run-d--name=server-http --link=server-db centos6.8-httpd/usr/bin/httpd--dforeground

At this time, we execute the Apache server to keep it in the background, while, in PHP configuration MySQL server name "Server-db", directly with the server-db name can be. You do not need to enter an IP address or something. Our server-http specifies that the server-db is connected. Server-db in Server-http will be treated as a DNS resolution to obtain the appropriate connection IP.

Case 7, we want to expose Server-db,server-http port, let everyone access [HTML] view plain copy [root@centos7.2 ~] #docker run-d--name= Server-db-p 3306:3306 Centos6.8-mysql/usr/bin/mysql_safe–d

At this time we specified the server host 3306 port mapped to the container port 3306, exposed.

[root@centos7.2 ~] #docker run-d--name=server-http--link=server-db-p 8080:80centos6.8-httpd/usr/bin/httpd-- Dforeground

At this time we specified the server host 8080 port mapped to the container 80 port, exposed.

Case 8, we want to mount the host's database directory/server/mysql-data to server-db [HTML] view plain copy [root@centos7.2 ~] #docker run-d-- Name=server-db-p 3306:3306-v/server/mysql-data:/mysql-data centos6.8-mysql/usr/bin/mysql_safe–d

At this time, you will find that in the SERVER-DB root directory you will find a new folder Mysql-data, while the contents of the file and host under/server/mysql-data the same.

Case 9, we want a container to be automatically deleted immediately after its process is finished. [HTML] view plain copy [root@centos7.2 ~] #docker run-it--rm centos6.8

At this point we enter the container's console and when we exit the console inside the container, the container is terminated and automatically deleted.

Some of the above examples are some of the parameters and methods we use. Hope to help everyone.

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.