install docker
curl -s https://get.docker.com|sh
so slow...an hour...
start docker
First execute the command docker version to come:
docker version
It is found that the docker server is not started, execute the command:
service docker start
Then check the docker version again
docker pull command
The pull command is used to pull images
You can use the docker pull --help command to view help
The red underlined part has already marked the usage format of the command
-a : pull all tagged images --disable-content-trust : Ignore image verification, enabled by default
docker images command
Can view local mirrors
Similarly, you can also use docker images --help to view specific usage help
-a : List all local images (including intermediate image layers, by default, the intermediate image layers are filtered out) --digests : Display digest information for mirrors -f : show mirrors that meet the conditions --format : The template file specifying the return value --no-trunc : show full mirror information -q : show only mirror ID
docker run command
-a stdin: Specify the content type of standard input and output, optional STDIN/STDOUT/STDERR three items -d: run the container in the background and return the container ID -i: run the container in interactive mode, usually used with -t -t: reassign a pseudo input terminal for the container, usually used with -i --name="nginx-lb": specify a name for the container --dns 8.8.8.8: Specify the DNS server used by the container, the default is the same as the host --dns-search example.com: Specify the container DNS search domain name, the default is the same as the host -h "mars": specify the hostname of the container -e username="ritchie": set environment variables --env-file=[]: Read environment variables from the specified file --cpuset="0-2" or --cpuset="0,1,2": bind the container to run on the specified CPU -m : Set the maximum memory used by the container --net="bridge": Specify the network connection type of the container, support bridge/host/none/container: four types --link=[]: add link to another container --expose=[]: expose a port or a group of ports
docker hello world
Next, we will demonstrate using docker to run a hello world.
docker pull hello-world
If no version is specified when pulling, the latest version will be pulled
Next, use the docker images command to view the downloaded image
Use the run statement to run the hello-world image just now
docker run hello-world
docker install nginx
The Nginx page in the docker official repository: https://hub.docker.com/r/library/nginx/tags/
docker pull nginx:1.12.2
Download it for a while... When it's done, use the docker images command to check it out:
Use the run -d command to make nginx run in the background (so as not to cause nginx to stop running after the terminal window is closed)
-p 7788:80 means, map port 80 in the docker container to port 7788 of the host when running
docker run -d -p 7788:80 nginx:1.12.2
Use the docker ps command to view the currently running docker instance:
docker ps
The ID of the container is edb334b917cc, which will be used later
You can think of docker as a newly installed virtual machine. But how to enter this instance to operate?
docker exec -it <id> bash
Among them, docker exec is the instruction, -it is the parameter, id is the id of the docker instance, and bash is the operation performed on this instance, because here I want to open the bash of this instance to perform system operations and the like.
In this way, you enter the bash of this Nginx instance, and you can perform a series of shell commands. In fact, it is similar to operating a new virtual machine.
You will notice that when I entered the docker exec command, I did not write all the docker id. Because it is only necessary to uniquely determine the docker instance based on the id, there is no need to write all.
Just to introduce the exec command, which is not used yet. If it is already in, then exit exits the bash terminal of the Nginx instance.
Execute netstat -na | grep 7788 on the host to see if the port 7788 bound when Nginx was started just now works.
You can see that port 7788 is listening.
Next, open a browser on the host, enter the ip + port of your host, and verify it. If you see Nginx, it means success: