Mirror Warehouse Operation

grammar

#Log in to the mirror repository
docker login [OPTIONS] [SERVER]
Copy the code

The OPTIONS:

  • -u: indicates the login user name
  • -p: indicates the login password
#Log out of the mirror warehouse
docker logout [OPTIONS] [SERVER]
Copy the code
#Search the repository for images
docker search [OPTIONS] TERM
Copy the code

The OPTIONS:

  • — Automated: Lists only the images of the automated Build type
  • –no-trunc: displays the complete image description
  • -f < Filter criteria >: Lists the mirrors whose collections are not less than the specified value
#Pull the warehouse image
docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Copy the code

The OPTIONS:

  • -a: Pulls all tagged mirrors
  • –disable-content-trust: indicates that mirror verification is ignored. This function is enabled by default
#To upload a local image to the image repository, log in to the image repository first
docker push [OPTIONS] NAME[:TAG]
Copy the code

The OPTIONS:

  • –disable-content-trust: indicates that mirror verification is ignored. This function is enabled by default

The instance

Log in to Docker Hub

Docker login -u Username -p PasswordCopy the code

Logout Docker Hub

docker logout
Copy the code

Docker Hub find all images whose names contain Java and whose favorites are greater than 10

docker search -f stars=10 java
Copy the code

Parameter Description:

NAME: indicates the NAME of the mirror repository source

DESCRIPTION: indicates the DESCRIPTION of the mirror

OFFICIAL: Is it OFFICIAL with Docker

Stars: Similar to Github star, which means to like or like

AUTOMATED: Automatic construction

Download the latest Java image from Docker Hub

docker pull java
Copy the code

Download REPOSITORY from Docker Hub for all images of Java

docker pull -a java
Copy the code

Upload the local image myapache:v1 to the image repository

docker push myapache:v1
Copy the code

Local Image Management

grammar

#Listing local Mirrors
docker images [OPTIONS] [REPOSITORY[:TAG]]
Copy the code

The OPTIONS:

  • -a: Lists all local images (including the intermediate image layer, which is filtered by default)
  • –digests: Display ests of images
  • -f: displays mirrors that meet the conditions
  • –format: specifies the return value of the template file
  • –no-trunc: displays complete mirror information
  • -q: Displays only the mirror ID
#Delete (one or more) local mirrors
docker rmi [OPTIONS] IMAGE [IMAGE...]
Copy the code

The OPTIONS:

  • -f: Forcible deletion
  • –no-prune: The process mirror of the mirror is not removed. It is removed by default
#Mark the local image to a repository
docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
Copy the code
#View the creation history of a specified mirror
docker history [OPTIONS] IMAGE
Copy the code

The OPTIONS:

  • -h: prints the image size and date in a readable format. The default value is true
  • –no-trunc: Displays complete commit records
  • -q: Lists only the ID of the submission record
#The build command is used to create an image using Dockerfile
docker build [OPTIONS] PATH | URL | -
Copy the code

The OPTIONS:

  • –build-arg=[] : Sets variables for image creation
  • –cpu-shares: sets CPU usage weight
  • –cpu-period: limits the CPU CFS period
  • –cpu-quota: limits the CPU CFS quota
  • –cpuset-cpus: specifies the CPU ID to be used
  • –cpuset-mems: specifies the memory ID to be used
  • –disable-content-trust: disables verification and is enabled by default
  • -f: Specifies the Dockerfile path to use
  • –force-rm: delete the intermediate container during the mirroring process
  • — Isolation: Uses container isolation technology
  • –label=[] : Sets the metadata used by the mirror
  • -m: Sets the maximum memory size
  • –memory-swap: Set the maximum value of the swap to memory +swap. “-1” indicates no limit on swap
  • –no-cache: the process of creating a mirror does not use cache
  • –pull: Attempts to update a new version of the image
  • –quiet, -q: indicates the quiet mode. After the mode succeeds, only the mirror ID is displayed
  • –rm: Delete the intermediate container after the mirror is successfully configured
  • –shm-size: sets the size of /dev/shm. The default value is 64 MB
  • –ulimit: ulimit configuration
  • — Squash: Squash all operations in a Dockerfile into a single layer
  • –tag, -t: the name and tag of the image, usually in the name:tag or name format. Multiple tags can be set for an image in a single build
  • –network: default Default Sets the network mode of the RUN directive during build
#Saves the specified image as a tar archive
docker save [OPTIONS] IMAGE [IMAGE...]
Copy the code

The OPTIONS:

  • -o: indicates the output file
#Import the image exported using the docker save command
docker load [OPTIONS]
Copy the code

The OPTIONS:

  • –input, -i: Specifies the file to import, instead of STDIN
  • –quiet, -q: condenses the output information
#Create an image from the archive
docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
Copy the code

The OPTIONS:

  • -c: Apply the Docker command to create an image
  • -m: description of submission

The instance

View the list of local mirrors

docker images
Copy the code

Lists the images in the local image whose REPOSITORY is Ubuntu

docker images  ubuntu
Copy the code

Forcibly delete the local image runoob/ Ubuntu: V4

docker rmi -f runoob/ubuntu:v4
Copy the code

Mark the image Ubuntu :15.10 as runoob/ Ubuntu: V3 image

Docker tag ubuntu: runoob/ubuntu 15.10: the v3Copy the code

View the creation history of the local image Runoob/Ubuntu: V3

docker history runoob/ubuntu:v3
Copy the code

Create an image using the Dockerfile of the current directory labeled Runoob/Ubuntu :v1

docker build -t runoob/ubuntu:v1 . 
Copy the code

Create the image using the Dockerfile at the URL github.com/creack/docker-firefox

docker build github.com/creack/docker-firefox
Copy the code

You can also specify the location of the Dockerfile file by using -f

docker build -f /path/to/a/Dockerfile .
Copy the code

Before the Docker daemon executes the instructions in the Dockerfile, it first checks the syntax of the Dockerfile and returns any syntax errors

Docker build -t test/ myapp. Sending build context to docker daemon 2.048 kB Error response from daemon: Unknown instruction: RUNCMDCopy the code

Generate the my_ubuntu_v3.tar file from runoob/ Ubuntu :v3

docker save -o my_ubuntu_v3.tar runoob/ubuntu:v3
Copy the code

Create an image from the image archive file my_ubuntu_v3.tar and name it runoob/ Ubuntu :v4

docker import  my_ubuntu_v3.tar runoob/ubuntu:v4
Copy the code

Container operation

grammar

#Lists running containers
docker ps [OPTIONS]
Copy the code

The OPTIONS:

  • -a: Displays all containers, including those that are not running
  • -f: filters the displayed content based on conditions
  • –format: specifies the return value of the template file
  • -l: displays the newly created container
  • -n: lists the n containers created recently
  • –no-trunc: does not truncate the output
  • -q: displays only container ids in silent mode
  • -s: Displays the total file size
#Gets the metadata of the container/image
docker inspect [OPTIONS] NAME|ID [NAME|ID...]
Copy the code

The OPTIONS:

  • -f: specifies the returned value of the template file
  • -s: Displays the total file size
  • –type: Returns JSON for the specified type
#View information about processes running in a container. The ps command is supported
docker top [OPTIONS] CONTAINER [ps OPTIONS]
Copy the code
#Connect to a running container
docker attach [OPTIONS] CONTAINER
Copy the code
#Get live events from the server
docker events [OPTIONS]
Copy the code

The OPTIONS:

  • -f: filters events based on conditions
  • –since: Displays all events from the specified timestamp
  • –until: Running time displays until the specified time
#Get the container's logs
docker logs [OPTIONS] CONTAINER
Copy the code

The OPTIONS:

  • -f: tracks the output of logs
  • –since: Displays all logs from a start time
  • -t: displays the timestamp
  • –tail: Lists only the latest N container logs
#Block until the container stops, and then print out its exit code
docker wait [OPTIONS] CONTAINER [CONTAINER...]
Copy the code
#Export the file system to STDOUT as a tar archive
docker export [OPTIONS] CONTAINER
Copy the code

The OPTIONS:

  • -o: writes the input content to the file
#Lists the port mappings for the specified container, or looks for ports that NAT PRIVATE_PORT to the public
docker port [OPTIONS] CONTAINER [PRIVATE_PORT[/PROTO]]
Copy the code

The instance

Lists all running container information

$ docker psCONTAINER ID IMAGE COMMAND ... PORTS NAMES 09b93464c2f7 nginx:latest "nginx -g 'daemon off" ... 80/ TCP, 443/ TCP myrunoob 96f7f14e99ab mysql:5.6 "docker-entrypoint.sh"... 0.0.0.0:3306 - > 3306 / TCP mymysqlCopy the code

Output details:

CONTAINER ID: indicates the ID of a CONTAINER

IMAGE: IMAGE used

COMMAND: The COMMAND that is run when the container is started

CREATED: time when the container was CREATED

STATUS: indicates the STATUS of the container

There are seven states:

  • Created (already created)
  • Restarting
  • Running
  • Removing (on the move)
  • Paused
  • Exited (stop)
  • He was dead.

PORTS: container port information and connection type used (TCP \ UDP)

NAMES: automatically assigned container NAMES

List the five containers that were created recently

docker ps -n 5
Copy the code

Lists all created container ids

docker ps -aq
Copy the code

Obtain meta information about mysql:5.6

Docker inspect mysql: 5.6Copy the code

Gets the IP of the running container mymysql

 docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mymysql
Copy the code

View the process information of the container mymysql

Docker top mymysql run to see all the process of container information ` ` ` shell for I ` in docker ps | grep Up | awk '{print $1}' ` do echo \ && docker top $I doneCopy the code

The container Mynginx points the access log to standard output and connects to the container to view access information

docker attach --sig-proxy=false mynginx
Copy the code

Shows all docker events since July 1, 2016

docker events  --since="1467302400"
Copy the code

Show docker image as mysql:5.6 related events after July 1, 2016

Docker events -f "image"="mysql:5.6" --since="2016-07-01"Copy the code

Trace the log output of the container Mynginx

docker logs -f mynginx
Copy the code

View the latest 10 mynginx logs from July 1, 2016

docker logs --since="2016-07-01" --tail=10 mynginx
Copy the code

Save the container with id A404C6C174A2 as a tar file by date

docker export -o mysql-`date +%Y%m%d`.tar a404c6c174a2
Copy the code

Lifecycle management of containers

grammar

#Create a new container and run a command
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Copy the code

The OPTIONS:

  • -a stdin: specifies the standard input and output types. The options are stdin, STDOUT, or STDERR
  • -d: Runs the container in the background and returns the container ID
  • -I: Runs the container in interactive mode, usually in conjunction with -t
  • -p: indicates random port mapping. Ports inside a container are randomly mapped to ports on a host
  • -p: specifies the port mapping. The format is host (host) port: container port
  • -t: reassigns a pseudo-input terminal to the container. It is usually used together with -i
  • –name=”nginx-lb”: Specify a container name
  • — DNS 8.8.8.8: Specifies the DNS server used by the container. By default, it is the same as the host
  • –dns-search example.com: Specify the container DNS search domain name, which is the same as the host by default
  • -h “Mars “: specifies the hostname of the container
  • -e username=” Ritchie “: Sets environment variables
  • –env-file=[]: Reads environment variables from the specified file
  • — cPUSet =”0-2″ or –cpuset=”0,1,2″: bind the container to the specified CPU
  • -m: Sets the maximum memory usage of a container
  • – net = “bridge” : specify the container’s network connection type, support bridge/host/none/container: four types
  • –link=[]: Adds a link to another container
  • –expose=[]: Opens a port or group of ports
  • –volume, -v: Binds a volume
#Start one or more containers that have been stopped
docker start [OPTIONS] CONTAINER [CONTAINER...]
#Stop a running container
docker stop [OPTIONS] CONTAINER [CONTAINER...]
#Restart the container
docker restart [OPTIONS] CONTAINER [CONTAINER...]
Copy the code
#Kill a running container
docker kill [OPTIONS] CONTAINER [CONTAINER...]
Copy the code

The OPTIONS:

  • -s: sends a signal to the container
#Delete one or more containers
docker rm [OPTIONS] CONTAINER [CONTAINER...]
Copy the code

The OPTIONS:

  • -f: deletes a running container forcibly through the SIGKILL signal
  • -l: Removes the network connection between containers, but not the containers themselves
  • -v: deletes the volume associated with a container
#Pause all processes in the container
docker pause CONTAINER [CONTAINER...]
#Restore all processes in the container
docker unpause CONTAINER [CONTAINER...]
Copy the code
#Create a new container without starting it
docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
Copy the code
#Execute commands in a running container
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Copy the code

The OPTIONS:

  • -d: Separated mode: Runs in the background
  • -I: Keeps STDIN open even without attaching
  • -t: Allocates a dummy terminal

The instance

Start a container in backend mode using the Docker image nginx: Latest and name the container mynginx

docker run --name mynginx -d nginx:latest
Copy the code

Start a container in backend mode using mirroring nginx: Latest and map port 80 of the container to a random port on the host

docker run -P -d nginx:latest
Copy the code

Start a container in backend mode, map port 80 of the container to port 80 of the host, and map the directory /data of the host to /data of the container

docker run -p 80:80 -v /data:/data -d nginx:latest
Copy the code

Bind port 8080 of the container and map it to port 80 of localhost 127.0.0.1

Docker run -p 127.0.0.1:80:8080/ TCP Ubuntu bashCopy the code

Use the image nginx:latest to start a container in interactive mode and run the /bin/bash command inside the container

docker run -it nginx:latest /bin/bash
Copy the code

Start the stopped container Myrunoob

docker start myrunoob
Copy the code

Stop the running container Myrunoob

docker stop myrunoob
Copy the code

Restart the container Myrunoob

docker restart myrunoob
Copy the code

Kill the running container Mynginx

docker kill -s KILL mynginx
Copy the code

Forcibly delete containers DB01 and DB02

docker rm -f db01 db02
Copy the code

Remove connection db from container nginx01 to container db01

docker rm -l db 
Copy the code

Delete container nginx01 and the data volumes mounted to the container

docker rm -v nginx01
Copy the code

Delete all containers that have been stopped

docker rm $(docker ps -a -q)
Copy the code

Stop the service of the database container DB01

docker pause db01
Copy the code

Restore the database container DB01 to provide services

docker unpause db01
Copy the code

Create a container using the Docker image nginx: Latest and name it Myrunoob

docker create  --name myrunoob  nginx:latest      
Copy the code

Run the /root/runoob.sh script in the container mynginx in interactive mode

docker exec -it mynginx /bin/sh /root/runoob.sh
Copy the code

Open an interactive mode terminal in the container Mynginx

docker exec -i -t  mynginx /bin/bash
Copy the code

View the ids of containers that are already running

docker ps -a 
Copy the code

Container rootfs command

grammar

#Create a new image from the container
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Copy the code

The OPTIONS:

  • -a: indicates the submitted mirror author
  • -c: Use the Dockerfile command to create the image
  • -m: description of submission
  • -p: Suspends the container at commit time
#Used to copy data between containers and hosts
docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
Copy the code

The OPTIONS:

  • -l: preserves the link in the source target
#Check for changes to the file structure in the container
docker diff [OPTIONS] CONTAINER
Copy the code

The instance

Save the container A404C6C174A2 as a new image and add the committer information and description information

docker commit -a "runoob.com" -m "my apache" a404c6c174a2  mymysql:v1 
Copy the code

Copy the host/WWW /runoob directory to the/WWW directory of container 96f7F14e99ab.

docker cp /www/runoob 96f7f14e99ab:/www/
Copy the code

Copy the host/WWW /runoob directory to container 96f7f14e99ab and rename it WWW.

docker cp /www/runoob 96f7f14e99ab:/www
Copy the code

Copy the/WWW directory of container 96f7f14e99ab to the/TMP directory on the host.

docker cp  96f7f14e99ab:/www /tmp/
Copy the code

View changes to the file structure of the container mymysql.

docker diff mymysql
Copy the code

Other commands

grammar

#Displays Docker system information, including the number of images and containers
docker info [OPTIONS]
Copy the code
docker version [OPTIONS]
Copy the code

The OPTIONS:

  • -f: specifies the returned value of the template file
#Ctrl+ P + Q exits the container and makes it run in the background
^p^q
Copy the code

The instance

View Docker system information.

docker info
Copy the code

The Docker version information is displayed

docker version
Copy the code

docker –help

Commands: attach Attach local standard input, output, And error streams to a running container streams local standard input, output, and error streams to a running container Commit Create a new image from a container's changes Cp Copy files/folders between a container And the local filesystem copies files/folders between a Container and the local filesystem create create a new container Diff Inspect Changes to files or directories on a container's filesystem Exec Run a command in a running Container Run the export export a container's command in a running container Filesystem as a tar archive export the filesystem of a container as a tar archive. History Show the history of an image Images import import the contents from a tarball to create a filesystem image Import the contents from a tarball to create a filesystem image Inspect Return low-level information on Docker objects inspect Return low-level information on Docker objects kill kill one Containers load an image from a tar archive or STDIN to load an image from a compressed archive or STDIN Login Log in to a Docker registry logout Log out from a Docker registry Fetch the logs of a Container Captures logs from a Container pause Pause all processes within one or more Containers Suspends all processes in one or more Containers port List port Mappings or a specific mapping for the container List the port mappings or specific mappings of the container. Ps List Containers List all containers Repository from a registry Push an image or a repository to a registry rename push an image or a repository to a registry rename Rename a container Rename a container restart restart one or more containers Restart one or more containers rm Remove one or more containers Remove one or more containers Rmi Remove one or more images Run run a command in a new container Run the save save one or more images command in a new container To a tar archive (streamed to STDOUT by default) Save one or more images to a compressed archive (streamed to STDOUT by default) Search Search the Docker Hub for images on streaming index Stats Display a live stream of containers stats Display a live stream of containers (s) Resource Usage Statistics Real-time stream of resource usage statistics on containers Stop Stop one or more running containers Stop one or more containers in operation tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE Create a tag that refers to SOURCE_IMAGE TARGET_IMAG top Display the running processes of a Container Displays all running processes in a container unpause unpause all processes within one or more containers Unsuspend all processes in one or more containers update Update Configuration of one or more containers Updates the configuration of one or more containers version Show the Docker version information Wait Block displays the version information of containers until one or more containers stop, Then print their exit codes block until one or more containers stop, and then print their exit codes Run 'docker COMMAND --help' for more information on a COMMAND.Copy the code