Common commands can be divided into the following types
1. Container life Cycle Management # Docker [Run|start|stop|restart|kill|rm|pause|unpause]
2. Container Operation Ops # Docker [Ps|inspect|top|attach|events|logs|wait|export|port]
3. Container rootfs Command # docker [Commit|cp|diff]
4. Mirrored warehouse # docker [Login|pull|push|search]
5. Local image Management # Docker [Images|rmi|tag|build|history|save|import]
6. Other commands # Docker [Info|version]
Image related Operations Command:
There are three ways to create a mirror
Create a container based on an existing mirror
Import based on local template
Create based on Dockerfile file
Commit to regenerate a new image based on a container that already has an image
# docker commit [OPTIONS] CONTAINER [Repository[:tag]]
-M,--message= "" Submit information to describe the content for mirroring
-A,--author= "" Author info
-P,--suspend container run when Pause=true commits
My_container:1 is the name and version of the submitted image
# docker Commit-m "Centos7 x64 first Image"-a "Loren" 33d619155d03 my_centos7:1
Import imports a container snapshot based on the local template, importing a container snapshot file into the local
# Cat Centos.tar | Docker import-test/centos:v1.0
Build creates a new image based on the Dockerfile file
# docker build [OPTIONS] PATH | URL | -
-T set the image name and its identification number
-F,--file=dockerfile specify Dockerfile file path
# docker Build-t Test:2-f/opt/
Search Image_name searching for Image in Docker index
--automated=false
-S N,--stars=0 specifies an image that evaluates to more than N stars
# Docker Search CENTOS6
Pull image_name from Docker Register Server drop-down Image or repository
# Docker Pull CentOS
# Docker Pull Centos:centos6
# Docker pull dl.dockerpool.com:5050/centos:6.8 specified website download
Push pushes an image or repository to registry
Before uploading, you should change the uploaded image's tag to hup username/image Name: Tag
Like # docker tag Centos6.8:v1 644597521/centos6.8:v1
Images show list of all mirrors on-premises
RMI deletes the mirror of the specified ID
Tag Modify image name
# Docker Tag Test:1 my_image:v2 modify the test mark to 1 with a name of my_image tag number of V2
Save image to local file
Usage:docker save [OPTIONS] image [Image ...]
-O,--output= ""
# docker Save-o Centos_6.4.tar centos6.4:v1 # Export local centos6.4:v1 image as Centos_6.4.tar file
Load imports local files into the local mirror library
Usage:docker load [OPTIONS]
-I,--input= ""
# Docker Load < Centos_6.4.tar # import Centos_6.4.tar files into the local mirror list
Inspect displays information about the image or container. Returns the JSON format information, if only one of the contents, you can use the-F to specify
Container Common Operations Command:
Run a new container
# usage:docker Run [OPTIONS] IMAGE [COMMAND] [ARG ...]
-A,--attack
-i,--interactive=false runs the container in interactive mode, usually with the-t collocation
-T,--Tty=false Assigning a pseudo-input terminal
-D Background Run
-P allows external access to all open ports on the container
-P port mapping-p 80:80
--name Specify the name of the container after launch
# docker Run-i-T CentOS
# docker Run-i-t-d Centos/bin/bash
# docker Run-i-t-d--name My_container Centos/bin/bash
# docker Run-i-t-d-P 80:80--name My_container Centos/bin/bash
-V,--volume=[] Create a data volume
/mnt creating a data volume in a container
/webapp:/src/webapp directory mount. Mount the local WebApp directory to the container's/src/webapp. Both the container and the host's Mount directory will change at the same time
/test.txt:/tmp/text.txt file mount. Mount the local/test.txt file to the/tmp/text.txt of the container (note that only the files within the container mount are modified, otherwise not synchronized)
# docker Run-ti-v/da--name=dbdata CentOS Create a container dbdata and create a data Volume Mount container dbdata the/da directory
--volume-from Sharing mounted data volumes
# docker Run-ti-v/mnt--name db CentOS Create a Data volume container db and create a data volume to mount to the/MNT directory of the container db
# docker Run-ti--volume-from=db--name db1 CentOS # DB1 containers mount data volumes in a DB container
# docker Run-ti--volume-from=db--name DB2 CentOS # DB2 containers mount data volumes in a DB container
At this time three containers DB,DB1,DB2 can share the directory/mnt
--link Connecting other containers
--link Name:alias name to establish the container name of the connection, alias of the container to which alias is connected
# Docker run-ti-d-P--name web--link lamp:lamp centos6.4/bin/bash new container web and already running container lamp connection
List of PS display containers
-A Show All information
-Q displays only the ID
# Docker Inspect 5d20c5528521 display container details
# docker Ps-a-Q ID
# Docker Inspect-f "{{. State.pid}} "5d20c5528521 displays the Pid of the running container
Stop|start|restart Stop | start | Restart container
exec enters the container (recommended)
# docker exec [OPTIONS] CONTAINER COMMAND [ARG ...]
# docker EXEC-T-I 216c623071b3/bin/bash
Attack container_id into the container
# Docker Attack 216c623071b3
Using the attach command is sometimes inconvenient. When multiple windows are attach to the same container at the same time, all Windows will be displayed synchronously. When a window is blocked by a command, other Windows cannot perform the action.
Nsenter
# yum Install Util-linux
# pid=$ (Docker inspect-f "{{. State.pid}} "5d20c5528521)
# nsenter--target $PID--mount--uts--ipc--net--pid
# nsenter--target 10981--mount--uts--ipc--net--pid
-T,--target <pid> target process to get namespaces
-M,--mount[=<file>] Enter mount namespace
-U,--uts[=<file>] Enter UTS namespace (hostname etc)
-I,--ipc[=<file>] Enter System V IPC namespace
-N,--net[=<file>] Enter Network namespace
-P,--pid[=<file>] Enter PID namespace
RM Deletes a container
-F,--force=true Force Delete
-L,--link=false delete the container's connection, but keep the container
-V,--volumes=false delete the container mounted data volume
Export the container, export a container that has been created to a file, regardless of whether the container is in a running state at this time
-O,--output= ""
# Docker Export 929bf12bc6ea > Centos_6.4_php.tar
Other common commands
Docker-h 127.0.0.1:1234-d & Modify the server to listen on the local TCP connection 1234 port
Volume managing Docker Files
Login Login Warehouse https://hub.docker.com/, after successful login information save file in user home directory/.docker/config.json
Enter the user, password, mail.
Download the. Bashrc_docker and put the content in the. BASHRC
# wget-p ~ Https://github.com/yeasy/docker_practice/raw/master/_local/.bashrc_docker;
# echo "[-F ~/.bashrc_docker] &&. ~/.bashrc_docker ">> ~/.BASHRC
# source ~/.BASHRC
This file defines a lot of easy-to-use Docker commands, such as Docker-pid to get the PID of a container;
And Docker-enter can enter the container or execute commands directly inside the container.
http://liumissyou.blog.51cto.com/4828343/1792500
This article is from the "System website Operations" blog, please be sure to keep this source http://cgc243652136qq.blog.51cto.com/3989433/1828725
Docker basic Commands