Docker installation configuration and use of the detailed

Source: Internet
Author: User
Tags docker ps docker run docker registry

Basic Concepts

Docker consists of three basic concepts

    • Image (Image)
    • Container (Container)
    • Warehouse (Repository)

By understanding these three concepts, you understand the entire life cycle of Docker.

1. Docker installation and start-up
# 安装docker# 配置文件 /etc/sysconfig/dockeron  # 加入开机启动# 启动docker服务# 基本信息查看version# 查看docker的版本号,包括客户端、服务端、依赖的Go等# 查看系统(docker)层面信息,包括管理的images, containers数等run -i -t centos /bin/bash
2, the acquisition of the mirror and the use of the container
# Search ImageDocker Search <image># Search for image in Docker index# Download ImageDocker Pull <image># drop-down image from Docker Registry server# View ImagesDocker Images:# list ImagesDocker Images-a# List all the images (including history)Docker RMI <image Id>:# Delete One or more image# Creating Containers with mirrorsDocker Run-i-T SAULOAL/UBUNTU14. GenevaDocker Run-i-T SAULOAL/UBUNTU14. Geneva/bin/bash# Create a container where you run the Bash app and exit the container close# View ContainerDocker PS: Lists all currently runningContainerDocker ps-l: Lists the most recently launchedContainerDocker ps-a: Lists allContainer(Contains history, that is, a runningContainerDocker ps-q: Lists the last runningContainerId# Start the container againDocker Start/stop/restart <Container>#: Open/Stop/restart containerDocker start [container_id]#: Run a container again (including historical container)Docker attach [container_id]#: Connect a running container instance (that is, the instance must be the start state, multiple windows can attach a container instance at the same time)Docker Start-i <Container>#: Start a container and enter interactive mode (equivalent to start first, in attach)Docker run-i-T <image>/bin/bash#: Create container with image and enter interactive mode, login shell is/bin/bashDocker Run-i-t-p #: Map the HOST port to the container to facilitate external access to the container service, Host_port can be omitted, omitting the container_port mapping to a dynamic port.     #注: Use start to start a container that has already been created, and use Run to open a new container through the image. # Delete ContainerDocker RM <Container...>#: Delete one or more containerDocker RM ' Docker ps-a-Q '#: Delete all the containerDocker Ps-a-Q | Xargs Docker RM#: Ibid., delete all container
Enter container-nsenter command

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 Installation
The Nsenter tool is included after the Util-linux package version 2.23. If the Util-linux package in the system does not have this command, you can install it from the source code in the following way.

https://www.kernel.org/pub/linux/utils/util-linux/v2.28/util-linux-2.28.tar.gz./configure --without-ncursesmake nsenter && sudo cp nsenter /usr/local/bin

Nsenter Use
Nsenter can access the namespace of another process. Nsenter requires root permission to work properly.
In order to connect to the container, you also need to find the PID of the first process of the container, which can be obtained by the following command.

PID=$(docker inspect --format"{{ .State.Pid }}" <container>)

With this PID, you can connect to this container:

nsenter--target$PID--mount--uts--ipc--net--pid

More simply, it is recommended to download the. Bashrc_docker and put the content in the. bashrc.

wget -Phttps://github.com/yeasy/docker_practice/raw/master/"[ -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;
Docker-enter can enter the container or execute commands directly within the container.

$(docker-pid <container>)docker-enter <containerlsdocker-enter <container> bash
3. Persistent containers and mirrors 3.1 Creating a new image from a container

A running image is called a container. You can modify the container (such as deleting a file), but these changes do not affect the image. However, you can use the Docker commit command to turn a running container into a new image.

docker commit <container> [repo:tag] # 将一个container固化为一个新的image,后面的repo:tag可选。
3.2 Persistence Container

Export command for persisting containers

export <CONTAINER ID> > /tmp/export.tar
3.3 Persistent Mirroring

The Save command is used to persist the image

docker save 镜像ID/tmp/save.tar

3.4 Importing Persistent container

Delete Container 2161509ff65e

2161509ff65e

Import Export.tar File

cat /tmp/exportimportexport:latest
3.5 Importing persistent image

Delete Image daa11948e23d

docker rmi daa11948e23d

Import Save.tar File

/tmp/save.tar

Hit tag on image

tag daa11948e23d load:tag
the difference between 3.6 export-import and Save-load

Images that are exported and then imported (Export-import) will lose all history, and the image saved and Reloaded (Save-load) does not lose its history and layers (layer). This means that you will not be able to roll back to the previous layer by using the export and then import, and then you can roll back the entire image using the save and reload method. (You can perform a Docker tag to roll back the previous layer).

3.7 Some other commands
$CONTAINER_ID #查看docker实例运行日志,确保正常运行    $CONTAINER_ID #docker inspect <image|container> 查看image或container的底层信息    docker build <path> 寻找path路径下名为的Dockerfile的配置文件,使用此配置生成新的image    docker build -t repo[:tag] 同上,可以指定repo和可选的tag    docker build - < <dockerfile> 使用指定的dockerfile配置文件,docker以stdin方式获取内容,使用此配置生成新的image    docker port <container> <container port> 查看本地哪个端口映射到container的指定端口,其实用docker ps 也可以看到
some tips for using Docker file storage directory

Docker actually puts everything under the/var/lib/docker path.

[root@localhost docker]# ls -Fcontainers/  devicemapper/  execdriver/  graph/  init/  linkgraph.db  repositories-devicemapper  volumes/

Containers Directory is of course the storage container (container), the graph directory storage image, the file layer (Files system layer) stored in the Graph/imageid/layer path, So that we can see exactly what is in the file layer and use this hierarchy to clearly see how the layers of the file layer stack up.

Reprint please be sure to keep this source: http://blog.csdn.net/fgf00/article/details/51893771

Docker installation configuration and use of the detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.