and data management container docker

1, the concept of
a container similar to a linux environment, is created by mirroring initiated, to be understood that the mirror layer created at the top layer is a readable and writable, the mirror itself is read-only, write the mirror does not change the container.

2, container management
to create a container of 2.1
#docker run -itd --name nginx1 nginx: latest
basic create these three parameters can carry itd, meaning indicated are as follows;
-i: Run vessel in interactive mode, usually with - t simultaneously;
-d: background container, and returns the container ID;
-t: a container reassign pseudo input terminal, typically used in conjunction with -i;

nginx1 and nginx: latest denote container name and image used to create, and you can see the new post is created and run the containers docker ps command

#docker run -itd --name nginx2 -p 8080: 80 nginx: latest
specified port mapping, mapping the port 80 to the container port of the host computer 8080; this can be achieved by a container access port 8080 to access the host of purpose

#docker run -itd --name nginx3 --cpus 1 nginx : latest
restrictions cpu maximum number of available cores

#docker run -itd --name nginx5 --cpu-shares 512 nginx: latest
set cpu weight, the default of 1024; or it is not set to 0, default values are used; if the containers 5 are default values 1024, the average allocation

#docker run -itd --name nginx4 -m 100m nginx : latest
to limit the maximum available memory

#docker run -itd --name nginx6 -m 100m --oom -kill-disable nginx: latest
by default, appear out-of-memory (OOM) error, system processes inside the container would kill to get a more much memory space; limits after using the container memory can be disabled oom-kill -m

Query 2.2 container
#docker ps
query currently running container

#docker ps -a
Here we turn off nginx1 containers docker stop nginx1, then use the -a can see all containers information

#docker ps -aq
query id numbers of all containers

#docker log nginx2
view of container logs

#docker inspect nginx2
for more information container query contains cpu, content, port, directories and other information

#docker top nginx2
process container query information

#docker port nginx2
view of the container port mapping

#docker stats nginx2
real-time view of the container resource utilization

2.3 operating container
#docker exec -it nginx2 bash
into the container, the container is still running after exiting the state

#docker cp /tmp/test.txt nginx2: / tmp
copy files to / tmp directory nginx2 container; copy the files in the container opposite to the host

#docker start | stop | restart nginx2
ie start, stop, restart vessel

#docker rm nginx2
delete the restart, before executing the need to ensure that container is stopped, otherwise fail rm

#docker commit nginx2 nginx: v2
will become a mirror submit container, the container will change the current persisted to nginx: v2 mirror

3. Data Management
3.1 volumes ways
#docker volume create nginx-vol
create volume, specify a name for nginx-vol

#docker volume ls
query volume has been created

#docker volume inspect nginx-vol
view detailed information volume, you can see the path to the mount

#docker run -itd --name nginxvol-test -p : 8081: 80 --mount src = nginxvol, dst = / usr / share / nginx / html nginx: latest
used to create volume container, the container mount directory is designated / usr / share / nginx / html

At this view nginx-vol will find the html file in the directory container mount; add files in the volume will be synchronized to the container

Docker inepct command can see the volume of container information

RM nginx-Vol Volume #docker
nginx-Vol when not in use can perform the removal

3.2 bind embodiment
#docker run -itd --name nginxBind-test -p : 8082: 80 --mount type = bind, src = / root / www /, dst = / usr / share / nginx / html nginx: latest
Create Container when carrying type = bind, and specify the directory src and dst

docker insepct can see the bind command information of the container

Guess you like

Origin blog.51cto.com/14129044/2427893