Detailed introduction to the installation and basic usage of Docker

  • 2020-05-27 07:40:22
  • OfStack

Docker is an ultra-lightweight virtual machine implemented in a novel way. It is still very different from VM in terms of implementation principle and application. It is technically known as application container (Application Container). (I personally prefer to call it a virtual machine.)

The Docker application container has the following advantages over VM:

It is fast to start, and the container usually starts in less than 1 second, while VM usually takes longer High resource utilization, 1 common PC can run thousands of containers, you run thousands of VM try Low performance overhead, VM typically requires additional CPU and memory to perform OS's functions, which takes up additional resources

Docker installation

Install Docker on CentOS6


# yum -y install epel-release

# yum -y install docker-io

Install Docker on CentOS7


# yum -y install docker

Start the Docker


# /etc/init.d/docker start

If there is no process after startup, the log appears:

/usr/bin/docker: relocation error: /usr/bin/docker: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference

Solutions:


# yum upgrade device-mapper-libs

Docker image management


# docker pull centos // from docker.com To obtain centos The mirror 

# docker images // See what mirrors are available locally 

# docker tag centos fansik // for centos The image setting label is fansik To continue using docker images You'll see more 1 Yes, that's right image id and centos the 1 sample 

# docker search [image-name] // from docker Warehouse search docker Mirror image, followed by keywords 

# docker run -t -i centos /bin/bash // Open the container with the image you downloaded, -i Means to open the container's standard input, -t Distribution of said 1 A dummy terminal -i and -t Put it in front of the mirror name 

When the image is modified, we can submit the image and regenerate it into a new version for local processing

docker ps // view the running container, plus the -a option to view containers that are not running

docker rmi centos // is used to delete the specified image, in which the following parameter can be tag. If it is tag, the tag is actually deleted. As long as the image is changed and there are other tag, the image will not be deleted

docker tag centos centos:fansik create 1 REPOSITORY for centos, TAG for fansik mirror

# docker rmi centos:fansik removes REPOSITORY to be centos, TAG to be the mirror image of fansik

The Docker image USES the container to generate the new image

Enter the container you created earlier

# docker ps-a; Look at what containers there are # docker start dad4e9070e2b start id for dad4e9070e2b container (id can be abbreviated to top) # docker exec - it dad4e9070e2b bin/bash into the container You can directly use yum to install the required software

After running docker run, we enter the container, we make some changes, like installing something, and then we create a new image for the container

docker commit-m "change "-a "somebody info" container_id(get id via docker ps-a) new mirror name

For example: docker commit - m "install httpd" - a "Aming dad4e9070e2b aming/centos

This command is a bit like svn submitted, some changes - m add 1 information, - for containers information dad4e9070e2b id a designated author, then the name for the new image

Docker creates an image based on a local template import

Extraction module and can be directly on the Internet to download a module (can copy the link and then directly wget) http: / / openvz org/Download/templates/precreated The command to import the image is: # cat ubuntu-15.10-x86_64-minimal.tar.gz | docker import-ubuntu Export the existing image as 1 file: # docker save-o fansik-httpd.tar httpd(warehouse name or mirror ID) Restore the local image with a backup file: # docker load --input fansik-httpd.tar or # docker load < fansik-httpd.tar Upload your image to the dockerhub website, but you need to register docker push image_name

The original link: http: / / www cnblogs. com/fansik p / 5526938. html


Related articles: