docker container basic use

 

1. Basic Operation

1.1 Help command

  docker version docker info docker --help

2. Mirror command

docker images listed on the local host mirroring

Description of each option:

  REPOSITORY: represents the repository of the source image

  TAG: Mirror labels

  IMAGE ID: ID mirroring

   CREATED: image creation time

  SIZE: image size

  The same warehouse source can have multiple TAG (do not specify TAG, will be the default name)

OPTIONS Description:

  -a: List all the local mirror (image-containing intermediate layer)

  -q: Show only image ID.

  --digests: display summary information mirroring

  --no-trunc: display the complete image information

docker search a name XXX mirror

  docker search [OPTIONS] mirrorname

  OPTIONS Description:

    --no-trunc: Complete image display described

    -s: Favorites list number is not less than the specified value of the mirror.

    --automated: automated build lists only type mirror;

Download image

docker pull mirroring name [: TAG]

 

Remove Mirror

  To delete a single

    image ID docker rmi -f

  To delete multiple

    docker rmi -f mirror name 1: TAG name Mirror 2: TAG

  Remove all

    docker rmi -f $(docker images -qa)

3. The container command

There are mirrors to create the container , which is the fundamental premise

  (Download a CentOS mirrors) docker pull centos

New and launch container (if every way to make this start, it will list the container inside, even though the command is also wrong)

    docker run [OPTIONS] IMAGE COMMAND

    $docker run -it centos /bin/bash

  OPTIONS Description

  * The OPTIONS * Description ( common ): Some ** is a minus, minus some two

    --name = "container for the new name": Specify a name for the container;

    -d: background container, and returns the container ID, or start the daemon i.e. container;

    -i: Run vessel in interactive mode, typically used in conjunction with -t;

    -t: reassign a pseudo input terminal into a container, normally used in conjunction with -i;

    -P: random port mapping;

    -p: Specifies the port mapping, the following four formats

        ip:hostPort:containerPort

        ip::containerPort

        hostPort:containerPort

        containerPort

Start an interactive container

  Mirroring centos: latest start a container in interactive mode, execute / bin / bash command within the container.

    $ docker run -it centos /bin/bash

    •   -t: Specifies a pseudo-terminal or terminals in the new container.

    •   -i: allows you to standard input (STDIN) in the container to interact.

    •   Interactively enter the [root @ c1a4b6a780a9 /] # display to enter the root directory. If, once a non-interactive way to start the container, the command will fail, so you need to quit before. ctrl + d, or exit to exit.

    •   After displaying [root @ rbtnode1 ~] # and can use commands such as docker see, so look at before it is best to start running container

Lists all currently running container

  After you start to see the container may be running, Docker PS is running, you can see their status , docker ps -a is a whole, including the container has withdrawn, and the time they create.

  docker ps [OPTIONS]

    docker ps --help for help

  OPTIONS Description (common):

    -a: lists all currently running container + run-off in history

    -l: display container recently created.

    -n: display the last n-created container.

    -q: Silent mode, only the container number.

    --no-trunc: do not cut output.

 

Exit container

   1;exit

    Container stop exit

   2.ctrl+P+Q

      The container does not stop exit

Start container

  docker start container or containers ID name

Restart container

  docker restart container or containers ID name

Stop the container

  docker stop container or containers ID name

Forced to stop container

  docker kill container or containers ID name

To delete a stopped container

  Container ID docker rm

Delete multiple containers

  docker rm -f $(docker ps -a -q)

  docker ps -a -q | xargs docker rm

 

View container logs

  ​docker logs -f -t --tail 容器ID

  docker run -d centos /bin/sh -c "while true;do echo hello zzyy;sleep 2;done"

 

    * -T is time stamped

    * -F to follow the latest log print

    * --Tail figures show how many final

Container processes running within view

   docker top container ID

Check the internal details of the container

   docker inspect containers ID

Running into the container and a command line interaction

    docker exec -it container ID bashShell (recommended)

Re-enter the docker attach the container ID

This distinction Attach directly to the container terminal start command will not start a new process
  exec is to open a new terminal in the container, and can start a new process

Copy files from the container to the host

  docker cp container ID: path to the destination host path within the container

Export and import container

Export Container

      If you want to export a container locally, you can use docker export command.

$ Docker export 1e560fca3906> centos.tar 
export containers 1e560fca3906 snapshot to a local file centos.tar.

Import Container Snapshot

 cat docker/centos.tar | docker import - centos

Problems:

Starting guard vessel

docker run -d container name

  Mirroring centos: Taiwan mode is activated after the latest in a container docker run -d centos question: Then docker ps -a view, will find that the container has exited It is important to note: Docker container running in the background, there must be a foreground process the command to run container if not those commands have been suspended (such as running top, tail), is automatically quit.

  This is a docker mechanisms, such as your web container, we nginx for example, under normal circumstances, we only need to configure the service to start to start the service response. For example, service nginx start, however, to do so, nginx runs as a background process mode, it causes the application is not running in the foreground docker, after such containers into the background, will immediately commit suicide because he felt he was a nothing to do. So, the best solution program that will run a background process of program you want to run before

 

 

 

 

 

Summary command:

attach Attach to under a running container # specified operating current mirror shell attach connector

build Build an image from a Dockerfile # Dockerfile through customized image

commit Create a new image from a container changes # submit this new image container

cp Copy files / folders from the containers filesystem to the host path # copies the specified file or directory from the container to the host

create Create a new container # create a new container, with the run, but do not start container

diff Inspect changes on a container's filesystem # docker container to see the changes

events Get real time events from the server # to obtain service from the docker container real-time event

exec Run a command in an existing container # running on the existing container command

export Stream the contents of a container as a tar archive # derived container content stream as a tar archive [corresponding to Import]

history Show the history of an image # show a mirror image formation history

images List images # lists the current system image

import Create a new filesystem image from the contents of a tarball # Create a new file system image from tar content package [Export correspond]

info Display system-wide information # information display system

inspect Return low-level information on a container # container View details

kill Kill a running container # kill 指定 docker 容器

load Load an image from a tar archive # image from a tar loading a package [corresponding to save]

login Register or Login to the docker registry server # register or log a docker source server

logout Log out from a Docker registry server # to exit from the current Docker registry

logs Fetch the logs of a container # container log output current

port Lookup the public-facing port which is NAT-ed to PRIVATE_PORT # view port mapping the source port corresponding to the inside of the container

pause Pause all processes within a container # 暂停容器

ps List containers # listed in the list of containers

pull Pull an image or a repository from the docker registry server # pulling specify the mirror or mirror the mirror from the source server docker

push Push an image or a repository to the docker registry server # push specify the mirror or mirror the source server to the docker

restart Restart a running container # restart operation of the vessel

rm Remove one or more containers # remove one or more containers

rmi Remove one or more images # remove one or more mirrors [no containers can delete the image, or need to delete the associated container in order to continue or forced to delete -f]

run Run a command in a new container # create a new container and run a command

save Save an image to a tar archive # a saved image of a tar bag [corresponding to the load]

search Search for an image on the Docker Hub # mirror docker hub in search

start Start a stopped containers # start container

stop Stop a running containers # stop the container

tag Tag an image into a repository # mirrored to the source tagging

top Lookup the running processes of a container # view the processes running in the container information

unpause Unpause a paused container # Unpause container

version Show the docker version information # View docker version number

wait Block until a container stops, then print its exit code # intercept exit status value when the container is stopped

Guess you like

Origin www.cnblogs.com/bufufan/p/11965433.html