Docker installation and error handling under Centos6.5

After reading the online installation, the error occurred
quote
Cannot connect to the Docker daemon. Is 'docker -d' running on this host?


The problem with the error is that the device did not exit normally due to unexpected power failure, and the left lck file affects the normal startup


---- Preconditions ----

Check the kernel
uname -r

The kernel below 3.8 needs to upgrade the

centos upgrade method
add kernel source
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org --deprecate
rpm -ivh http://www.elrepo.org/elrepo-release-6-5 .el6.elrepo.noarch.rpm
rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
yum -y --enablerepo=elrepo-kernel install kernel-lt

Manually downloaded kernel can only be saved as
https://www.kernel.org/
https://cdn.kernel.org/pub/linux/kernel/v3.x/linux-3.10.105.tar.xz
https:// mirrors.tuna.tsinghua.edu.cn/elrepo/kernel/el6/x86_64/RPMS/

Modify
vi /etc/grub.conf
and change default=1 to default=0 (Modify according to the actual display, the default new installation will be is 0)

Add software source
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

install Docker
yum -y install docker-io
yum -y install device- mapper

modifies the configuration file (see the final container running environment for details)
vi /etc/sysconfig/docker
other-args column is changed to: other_args="--exec-driver=lxc --selinux-enabled"

---- will go wrong Part----Due to abnormal shutdown, Docker will be abnormal and need to be handled manually.
Executing
/etc/init.d/docker status
returns
docker dead but subsys locked

needs to delete pid,sock
\rm /var/run/docker.*
\rm /var/lock/subsys/docker
executes
/etc/init.d/docker status and
returns
docker is stopped
----

check the version number
docker version

to start the service
service docker start


download centos and ubuntu
docker pull centos
docker pull ubuntu

view existing images
docker images

[root@localhost ~]# docker images    
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu latest 24c85647b066 35 hours ago 117.2 MB
centos latest 6cc2eba34ef6 7 days ago 192.5 MB

download file location
/var/lib/docker/

View
/var/lib/docker/devicemapper/devicemapper
, you can see the default 100G data file and 2G metadata file, but when you go to this directory and execute
du -h ,
you can see
[root@ localhost devicemapper]# du -h
639M .
The occupied space gradually increases according to the use, not a one-time overhead

. Access to the system
in the container can enter the container, so if you can access the docker host, ssh does not need
docker exec -it CONTAINER_ID /bin/bash

Run jenkins
to modify the mapping file first Permission to start the container
chown -R 1000:1000 /home/docker/jenkins
docker run -p 8090:8080 -p 50001:50000 -v /home/docker/jenkins:/var/jenkins_home jenkins
background run
docker run -d -p 8090:8080 -p 50001:50000 -v /home/docker/jenkins:/var/jenkins_home jenkins
running external port: port in container current file directory: file directory in container container
stop
docker stop CPID


enter container
docker exec -it ${ CPID} /bin/bash
to get CPID
docker ps

to get the running id of
jenkins docker ps|awk 'NR>1'|grep jenkins|awk '{print $1}'



---------- Dividing line----------

[Import and export] Refer to http://blog.csdn.net/a906998248/article/details/46236687
Use docker ps -a to view Export the existing container on the machine (using the value xxxx of the NAMES field)
export docker export xxxx > /home/xxxx-export-20170414.tar
import import docker import - /home/xxxx-export-20170414.tar

Use docker images to view this
Save docker save 123456 > /home/ubuntu-save-20170414.tar load
load docker load < /home/ubuntu-save-20170414.tar

difference:
export exported image The file size is smaller than the image saved by save. The
export (import import) is based on the image obtained by the container. When importing again, all the history of the image will be lost, so the rollback operation cannot be performed (docker tag <LAYER ID> <IMAGE NAME>); The image saved by save (loaded) has no history of losing the image and can be rolled back to the previous layer.
(View by: docker images --tree)
If you think it is inappropriate to import and load, you can use the docker rm container ID and docker rmi image ID to delete it.

【Delete all containers】
quote
docker kill $(docker ps -q) ; docker rm $(docker ps -a -q) ; docker rmi $(docker images -q -a) 


[View root password]
The password of the root user when the docker container starts is randomly assigned. So, in this way, you can get the password of the root user of the container.
docker logs 5817938c3f6e 2>&1 | grep 'User: ' | tail -n1

---- I am the dividing line ----
big handling http://www.jingyuyun.com/article/13953.htmlThe
core technology of the container refers to The technologies that make the container run on the host.
These technologies include container specification, container runtime, container management tool, container definition tool, registry, and container OS, which are introduced separately below.

[Container Specification]
Containers are not only Docker, but also other containers, such as rkt of CoreOS. In order to ensure the healthy development of the container ecosystem and the compatibility between different containers, several companies including Docker, CoreOS, and Google jointly established an organization called the Open Container Initiative (OCI), which aims to formulate open container specifications.
Currently OCI has released two specifications: runtime spec and image format spec.
With these two specifications, containers developed by different organizations and vendors can run on different runtimes. This ensures container portability and interoperability.
[Container runtime environment runtime]
The runtime is where the container actually runs. The runtime needs to work closely with the operating system kernel to provide a running environment for the container.
If you have used Java, you can understand the relationship between runtime and container in this way:
Java program is like a container, and JVM is like a runtime. The JVM provides the runtime environment for Java programs. In the same way, containers can only run at runtime.
lxc, runc and rkt are the three mainstream container runtimes.
lxc is an old container runtime on Linux. Docker also initially used lxc as the runtime.
runc is a container runtime developed by Docker itself, which conforms to the oci specification and is the default runtime of Docker now.
rkt is a container runtime developed by CoreOS and conforms to the oci specification, so it can run Docker containers.

[Container Definition Tool]
The container definition tool allows users to define the content and properties of a container, so that the container can be saved, shared and rebuilt.
docker image is the template of docker container, and runtime creates container according to docker image.
A dockerfile is a text file containing several commands that can be used to create a docker image.
ACI (App Container Image) is similar to docker image, except that it is the image format of the rkt container developed by CoreOS.

[Registry]
The container is created through the image, and there needs to be a warehouse to store the image uniformly. This warehouse is called the Registry.
Enterprises can build private registries with Docker Registry.
Docker Hub (https://hub.docker.com) is a hosting registry provided by Docker for the public. There are many ready-made images on it, which provides great convenience for Docker users.
Quay.io (https://quay.io/) is another publicly hosted Registry that provides similar services to Docker Hub.

[Container OS]
Due to the container runtime, almost all Linux, MAC OS and Windows can run containers. But this did not prevent the advent of container OS.
A container OS is an operating system dedicated to running containers. Compared to regular OS, container OS is usually smaller and starts faster. Because they are custom OSes for containers, they are usually more efficient at running containers.
There are already many container OSs, CoreOS, atomic and ubuntu core are outstanding representatives.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326526984&siteId=291194637