Docker Basic Concepts
Docker is an open source application container engine that allows developers to package their apps and dependencies into a portable container, and then publish it to any popular Linux machine.
Docker is an open platform for redefining the process of program development testing, delivery, and deployment, and Docker can be called a build once and run everywhere, which is Docker's proposed building Once,run anywhere
Creating mirrors
There are three ways to create a mirror:
Created based on existing container
Import based on local template
Based on Dockerfile
Created based on existing container
The main use of the Docker commit command, command format:
Docker commit [OPTIONS] CONTAINER [Repository[:tag]], mainly including:
-A,--author= "" Author information
-M,--message= "" Submit message
-P,--suspend container when Pause=true commits
For example:
# docker run-it Centos/bin/bash
[root@d7e7ac1cbca2/]# Touch Test
[root@d7e7ac1cbca2/]# ls
Anaconda-post.log Bin Dev etc home Lib lib64 lost+found media mnt opt proc root run sbin SRV sys test tmp usr var
# do Cker commit-m "Add a File"-a "Kafeikele" De6 centos_copy
5d318afa9e6f7fdb755db97e29e3860b752f24b0b50e6bfa0b7e457450802c0e
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos_copy latest 5d318afa9e6f seconds ago 196.7 MB
Import based on local template
It is recommended that you use the templates provided by OpenVZ to create
https://openvz.org/Download/templates/precreated
#cat Centos-7-x86_64-minimal.tar.gz.crdownload | docker Import-centos:latest
Save and import Mirrors
# Docker Images
CentOS 7.1.1503 47a77536ad4c 8 weeks ago 212.1 MB
# docker Save-o Centos_7.1.tar centos:7.1.1503< c3/># Docker load--input centos_7.1.tar
# Docker Load < Centos_7.1.tar
Based on Dockerfile
After the content of detailed introduction
Run the first Docker container
# Docker run CentOS echo "Hello World"
unable to find image ' centos:latest ' locally
latest:pulling from Centos
47d44cb6f252:pull Complete
168a69b62202:pull complete 812e9d9d677f:pull complete
: Pull Complete
ce20c473cd8a:pull complete centos:latest:The image you are pulling has been
. Important:image verification is a tech preview feature and should
.
Digest:sha256:3aaab9f1297db9b013063c781cfe901e2aa6e7e334c1d1f4df12f25ce356f2e5
status:downloaded Newer Image for Centos:latest
Hello World
Command Description:
Docker run: Standard container launch command
CentOS: Mirror name, default is latest
Echo and subsequent content: command to execute after the container starts
Start an interactive container
Docker run-it Centos/bin/bash
* Note:-T indicates that a pseudo terminal or terminal is specified in the Heart container and the-I label allows us to interact with stdin within the container
Start a Docker container in a service way
If you're actually testing, it's also estimated that the first "Hello World" container was launched after the echo command was executed, and the second interactive container, as long as the user exited the current container bash, also exited the container. This obviously does not meet the long running requirements of a service, easy to find Docker run provides the '-d ' parameter, you can implement the container as a daemon to start.
Docker run-d Centos/bin/bash-c "while true; do Echo Docker,hello world; Sleep 2; <br>179fc7f17c358834364d23112aa26d6a9e1875b2281563720425f62a8f1b5c33
This long string is called the container ID. It is the unique identifier of the container, so we can use it to manipulate containers, such as viewing logs, stopping or deleting containers, and so on.
Dock Logs 179fc7f17c358834364d
And why use a dead loop to output it?
Because if it's not a dead loop, after one output, the process in the container ends. The container's only process is over, and the container stops. So if you want to run a specific service in a container, the service itself must be running in the container in a daemon way.
Docker run [OPTIONS] IMAGE [COMMAND] [ARG ...]
Main options:
-D: Running the container in the background
-T: Provides a pseudo terminal
-I: Provides interactive input, typically used with "-T", and if only the "-i" option is available, the container cannot be exited after it is started
-V: Maps a volume to a container, such as:-p/data/www:/var/www/html
-P: Maps container ports to host hosts, such as:-P 8,080:80
More Command actions
# Docker images list all local mirrors # Docker search CentOS from the default mirrored warehouse searching for mirror NAME DESCRIPTION stars official automated the CentOS Build of CentOS. 2767 [OK] ansible/centos7-ansible ansible on Centos7 [OK] jdeathe/centos-ssh CentOS-6 6.8 x86_64/centos-7 7.2.1511 x 8. [OK] jdeathe/centos-ssh-apache-php CentOS-6 6.8 x86_64-apache/php/php M ... [OK] Nimmis/java-centos this are docker images of CentOS 7 with dif ... [OK] consol/centos-xfce-vnc CentOS container with "headless" VNC Sessi ... [OK] #docker pull CentOS Download mirrored to local #docker create-it ubuntu:latest create a container unable to find image ' ubuntu:latest ' locally l Atest:pulling from Ubuntu 58488e45273c:pull complete 25810b66099e:pull complete 6571ba684f54:pull complete 6ed49a73 D8f0:pull Complete C53777cbfc31:pull Complete 56465e1e45d2:pull complete
3a3cf4510de25c47b05b6819d61e2e2b5420 status:downloaded newer image for Ubuntu:latest 1330233e50aba7fca99e5914bd28dd89321bc86ec35fb36The container created by the b4775d3424337c190 Docker create command is in a stopped state and needs to be started with Docker start # Docker ps-a CONTAINER ID IMAGE command CREATED statu S PORTS NAMES 1330233e50ab ubuntu:latest "/bin/bash" about a minute ago Happy_engelbart Docker Run command is equivalent to executing the Docker create command first And then execute the Docker start command # docker run Ubuntu/bin/echo ' Hello World ' Hello World
Enter the container
Method One:
# Docker attach a54615a88787 followed by the container name or ID, exit after the Docker container also exits, not commonly used
Method Two:
# docker exec-it A54615a88787/bin/bash with a container name or an ID
Method Three:
Yum-y install Util-linux
# Docker Inspect--format ' {{. State.pid}} "Stupefied_cray the last Face is the name of the container
4899
# nsenter--target 4899 the--mount--uts--ipc--net--pid
Script
#!/bin/bash
cname=$1
cpid=$ (Docker inspect--format "{{. State.pid}} "$CNAME)
nsenter--target $CPID--mount--uts--ipc--net–pid
The above is a small set to introduce Docker Basic command detailed, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!