# Run docker#-it represents the front end running Docker run-it centos/bin/Echohaha# back end runs and maps 80 port Docker run-dt-p the: the--name Mycentos my/os# port mapping, IP access restrictions Docker run-dt-p127.0.0.1: the: the--name Mycentos my/os# do not create container run Dockerdocker runs--RM-it centos/bin/Echohaha# Create container, a name for Docker run-it--name Testecho centos/bin/Echohaha# renaming imagedocker tag image_name new_image_name# running the CentOS terminal Docker run-it centos/bin/bash# container Renaming docker rename Nginx nginx_1#------------------------------------------------------------# exit #------------------------------------------------------------# on Docker's CentOS terminal exit, this exit will stop containerexit# without stopping container exit method shortcut key: Ctrl+ P, Ctrl +q#------------------------------------------------------------# Run container#------------------------------------------------------------# Run the Docker CentOS terminal that has exited to the Docker start 0a2b06b59448# run and attach to Containerdocker start-I containerid# stop the running Docker CentOS Terminal Docker stop 0a2b06b59448# attached to the Docker terminal container, provided this container is already running in Docker Attach 3b6165b7504a# lists all the ContainerdockerPS-a# Print Docker's running terminal shows Docker logs 81a4f43c74ed# delete ContainerdockerRM3b6165b7504a# Delete all ContainerdockerRM$ (DockerPS-a) # list all mirrors Docker images# search mirror docker searches centos# download mirror docker pull centos# submit Mirror Docker commit Mycentos my/os:latest#------------------------------------------------------------# Image Import Export and run #------------------------------------------------------------# import Container as image file Docker export 3b6165b7504a> CentOS.Tar# import MirrorCatCentos.Tar| Docker Import-test/centos:v1.0# Run the imported mirrored Docker run-it Test/centos:v1.0/bin/bash# Removing mirrored docker RMI test/centos:v1.0# View Docker information, including installation path, CPU, memory, etc. dockerInfo# Container Execute command, enter container terminal Docker exec-it containerid bash# into the container terminal Nsenter--Mount--uts--IPC--net--pid--target $ (Docker inspect--format"{{. State.pid}}" "4cd5af004a52") # View port mappings for container Docker Port containerid#------------------------------------------------------------# Dynamic setting of environment variables at runtime # using parameters--Env# View Container's environment variable method to run the command in Container bash:Env#------------------------------------------------------------# View Container environment variables Docker exec-it NginxEnv# View Container's host file Docker exec-it NginxCat/etc/hosts# Setting the environment variable for container Docker run--RM-it--name Test--EnvMyhome=/home--EnvTest=/home--EnvPath= $PATH:/Home CentOS bash# can also use inspect to view container's environment variables Docker inspect nginx#------------------------------------------------------------# port mappings, IP access Restrictions #------------------------------------------------------------Docker Run-dt-p127.0.0.1: -: the--name Jetty Img_jettydocker Run-dt-p127.0.0.1: the: the--name Jetty1 Img_jettydocker run-dt-p the: the--name nginx--link Jetty:java--Link JETTY1:JAVA1 img_nginx#------------------------------------------------------------# Image Save and Reload #------------------------------------------------------------# Save Mirrored Docker save Img_java> Img_java.Tar# Reload Mirrored Docker load< Img_java.Tar# Query Mirroring History Docker Historical img_java# View image information Jsondocker inspect img_java#------------------------------------------------------------# file Copy #------------------------------------------------------------# Copy files from container autorun.sh to host/Home Directory # can also be directory replication DockerCPTest:/etc/init.d/autorun.SH/home# copy files or folders from host to container host # Use SCP command, if no SCP is installed, use YumInstallopenssh-clients# first needs to use Docker exec to enter the container terminalSCP-RP [email protected]192.168.0.35:/home/jetty8/*/home/#------------------------------------------------------------# Mount Data Volume # parameter privileged=true: Meaning to add privileges to the container, For example, read and write to mount volume # mount multiple data volumes, you can use multiple-v#------------------------------------------------------------# to create a data volume container and mount the directory Docker run -it--privileged=true-v/home/jetty8:/home/jetty8--name jetty CentOS bash# Creating a new data volume container using a data volume container docker run-it--privileged= True--volumes-from jetty--name os centos bash#------------------------------------------------------------# Create a mirror using dockerfile #------------------------------------------------------------# Note The following is not a small amount:. Docker build-f Dockerfile-t My/centos.
[Linux]-Docker common commands