Docker basic operations

Source: Internet
Author: User
Tags one more line custom name docker ps docker hub docker registry

Docker is based on Linux 64bit, cannot be used in Windows/unix or 32bit Linux environments.

so Docker is only in the 64 system. container virtualization is lighter than traditional virtualization. Easy to migrate, platform dependency is not strong. is only a service or module of the system.

Docker Core Concepts

1. Mirror, read-only template, like an ISO file for our system.

2. Container, mirrored like the virtual machine itself, so we say the container loads the mirror.

3. Warehouse, a place to store the image, divided into private warehouses and public warehouses. The largest public warehouse is the Docker hub (hub.docker.com), a domestic public warehouse (dockerpool.com).

4. Install Docker (CentOS as a column, divided into centos6,7)

CENTOS6 Installation

Yuminstall-y Epel-release

Yuminstall-y Docker-io

Installation on CENTOS7

Yum Install-y Dockerl

Start Dockerl

/etc/init.d/dockerstart


5.docker Basic Operation

Docker pull CentOS//Get CentOS image from docker.com

Docker images//See which mirrors are locally

Docker tag CentOS liu123//For CentOS Mirroring set label to Liu123, then use Docker images to view will come out one more line, diverted imageID and CentOS as

Docker search [Image-name]//searching Docker image from Docker repository, followed by keywords

Docker run-t-I centos/bin/bash//Use the downloaded image to open the container,-I means that the container's standard input opens,-t for assigning a pseudo terminal, to put-i-t in front of the mirror name

Once the image has been modified, we can submit the image to a new version to be rebuilt locally.

Dockerps//View the running container, plus the-a option to view containers that are not running

Dockerrmi CentOS//is used to delete the specified image, where the following parameters can be tag, if it is a tag, the actual deletion of the tag, as long as the image has other tags, the image will not be deleted. When the following parameter is the mirror ID, the entire image is completely deleted, and all the tags are removed together


6. Once a mirror is loaded, and then Docker Run-it Centos/bin/bash in, after installing some installation packages, you can generate a mirror of your own.

Dockercommit-m "Change somth"-a "Somebody info" container_id (get ID by dockerps-a) New image name

For example: Docker Commit- m "Install httpd"-A "aming" 2c74d574293f Liuwenzhi

This command is a bit like SVN's commit,

-M plus some change information,

-a specify author-related information

2c74d This string is the container ID, which is available through Docker ps-a

Back to the name of the new mirror


7. Export the image to a file, mirroring the migration

Docker Save-o Centos.tar CentOS


Note: container migration

Docker Export container_id > File.tar


Container Import

Cat File.tar |docker Import-liuwenzhi generate Liuwenzhi the image


8. Restore the local image using the file you just exported

Docker load--input Centos.tar or docker load <centos.tar


9.docker create-it CentOS//This can create a container, but the container does not start


Docker start container_id//Start container, you can use Dockerps to see, there is a start there is stop, and restart


Previously we used a Docker run equivalent to create and start

Docker run-i-T CentOS Bash


This enters a virtual terminal, we can run some commands, exit the Bash with command exit or CTRL d, and the container will stop when it exits.

Docker run-d allows containers to run in the background


Docker run--name web-itd CentOS Bash//--name give container custom name

10.docker logs container_id Viewing the history of a container


11. Into a backstage, Docker attach container_id this exit after the container also exits, not recommended.


12.docker exec-it container_id Bash into the background to run the machine


13. command to delete a container

Docker RM container_id

To delete a mirrored command

Docker RMI



14. Uploading to the local mirror

Dockerpull Registry//Download Registry image, registy an image for Docker, which we can use to create a local Docker private repository.


Dockerrun-d-P 5000:5000 registy//Start container in registry mirror, listen on port 5000


curl127.0.0.1:5000//can access it


Now let's upload one of the mirrors to the private repository.

Dockertag aming_test 172.7.15.106:5000/centos//Tag tag, you must have a private warehouse Ip:port


Docker push 172.7.15.106:5000/centos//This error is similar to the following

Error response from Daemon:invalidregistry endpoint https://172.7.15.106:5000/v0/: Unable to ping registryendpoint HTTPS ://172.7.15.106:5000/v0/
V2 Ping attempt failed with Error:get Https://172.7.15.106:5000/v2/:EOF
V1 Ping attempt failed with Error:get Https://172.7.15.106:5000/v1/_ping:EOF. If This private registry supports only the HTTP or HTTPS with a unknown cacertificate, please add '--insecure-registry 172.7. 15.106:5000 ' to the daemon ' sarguments. In the case of HTTPS, if you have access to the registry ' s Cacertificate, no need for the flag; Simply place the CA certificate AT/ETC/DOCKER/CERTS.D/172.7.15.106:5000/CA.CRT


This is because Docker, from the 1.3.X, interacts with the Docker registry by default with HTTPS, but the private repository built here only provides HTTP services, so when interacting with a private warehouse, the error is reported. To solve this problem, you need to increase the startup parameters to use HTTP access by default when starting Dockerserver. The workaround for this problem is:


Vi/etc/init.d/docker


Change $exec-D $other _args to

$exec-D--insecure-registry 172.7.15.106:5000 $other _args IP Here is the IP of the host

Then restart Docker

Service Docker restart


Start the registry container again

Docker start registry_container_id


Curlhttp://172.7.15.106:5000/v1/search//Can view all mirrors inside the private warehouse




15.docker of data management

Hanging in a local directory into Docker

Docker run-itd-v/data/:/data CentOS Bash//: The front/data is the directory of the host. Behind is the/data inside Docker.


16.

Defining Data Volume containers

Sometimes we need to share data between multiple containers, similar to NFS in Linux, so we can build a dedicated data volume container and then mount the data volume directly from other containers.


First, create a data volume container

Docker run-itd-v/data/--name Testvolaming/centos Bash//Note here/data/is the/data directory of the container, not the local/data/directory.


Then let the other container mount the data volume dockerrun-itd--volumes-from testvol aming bash

This article is from the "Liuliulinux" blog, make sure to keep this source http://zxlwz.blog.51cto.com/6952946/1769483

Docker basic operations

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.