Deploying Docker Records under Linux (1)-volume using

Source: Internet
Author: User
Tags unique id docker ps docker run

Before deploying the Linux deployment Docker record (0)-Infrastructure installation, next look at the use of Docker volume.

Docker Volume use
1) A data volume is a specially specified directory that leverages the container's UFS file system to provide some stable features or data sharing for the container. A data volume can be shared between multiple containers.
2) Create a data volume, as long as you follow the Docker Run command with the-v parameter to create a data volume , of course you can also follow multiple-v parameters to create multiple data volumes, when the container with the data volume is created. You can mount the data volume in other containers by using the--volumes-froms parameter, regardless of whether the container is running or not. You can also add one or more data volumes via the volume command in Dockerfile.
3) If you have some data that you want to share across multiple containers, or if you want to use that data in a few temporary containers, the best solution is to create a data volume container and then mount the data from that temporary container to the data volume container.

For example, the following:
start a named Xqsj_ Container container, this container contains two data volumes/var/volume1 and/var/volume2
Note that once the container is created, it does not enter the container, it only creates a single data volume, and after the two containers are created, you can enter the ~
[[email protected] ~]# docker run-v/var/volume1-v/var/volume2--name xqsj_ Container centos/bin/bash
[[email protected] ~]#

Create App_container container, mount the data volume in the Xqsj_container container
[email protected] ~]# docker run-t i--rm--volumes-from xqsj_container--name app_container centos/bin/bash
[[email protected]/]# ls/var/volume1                          //discover that both data volumes exist
[[email protected]/]# ls/var/volume2
[[email protected]/]# echo " This is volume1 ' >/var/volume1/test1
[[email protected]/]# echo "This is Volume2" >/var/volume1/test2

or create a container to mount the data volumes from the Xqsj_container mounted in the App_container
[Email protected] ~]# Docker run-t-i--rm--volumes-from app_container--name lastapp_container centos/bin/bash
[Email protected]/]# ls/var/volume1
Test1
[Email protected]/]# ls/var/volume2
Test2
[Email protected]/]# Cat/var/volume1/test1
This is volume1
[Email protected]/]# Cat/var/volume2/test2
This is volume2

List all the containers

[[email protected] ~]# Docker ps-acontainer ID        IMAGE               COMMAND             CREATED              STATUS                          PORTS                    namesb4c27e360614        CentOS              "/bin/bash"         seconds ago up       notoginseng seconds                                            Lastapp_ containerb9891bcdfed0        CentOS              "/bin/bash" about         a minute ago up about   a minute                                        app_ container1d6f0591b781        CentOS              "/bin/bash" about         a minute ago   Exited (0) about a minute ago                            Xqsj_containereaf66f1e43ab        CentOS              "/sbin/init"        2 hours ago up          2 hours                      0.0.0.0:8888-> 8080/tcp   Hungry_khorana

List the containers that are currently running

[[email protected] ~]# Docker PS CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS                    namesb4c27e360614        CentOS              "/bin/bash",         seconds ago up,       seconds                                Lastapp_ containerb9891bcdfed0        CentOS              "/bin/bash" about         a minute ago up about   a minute                            app_ Containereaf66f1e43ab        CentOS              "/sbin/init"        2 hours ago up          2 hours          0.0.0.0:8888->8080/ TCP   Hungry_khorana

You can add this Docker host to the Daocloud cloud platform to manage it, and you can see the container of the Docker host on the Daocloud and log in to the container's console.

Even if you delete the first Data volume container or the data volume container in the middle tier, the data volume will not be deleted as long as there are other containers using the data volume.

You can also mount the directory of a localhost as a data volume on a container , followed by the-v parameter behind the Docker run, but the-V is no longer a separate directory, it is [Host-dir]:[container-dir]:[rw|ro] In this format, Host-dir is the address of an absolute path, and if Host-dir does not exist, Docker creates a new data volume, and if Host-dir exists but points to a nonexistent directory, Docker also creates the directory. Then use the directory to do the data source. For example:
[This is described in this document that deploys Docker environment records under Linux]

You cannot use Docker export, save, CP, and other commands to back up the contents of a data volume because the data volume exists outside of the mirror, but there are always workarounds, as follows:
# Docker run-rm--volumes-from data-v $ (PWD):/backup busybox tar cvf/backup/backup.tar/data
Create a new container, mount the data volume container, mount a local directory, and then back up the data volume of the Remote Data volume container to the mapped local directory through the backup command.
--------------------------------------------------------------------------------------------------------------- -----------------------
Take note of the following four commands:
Open/Stop/restart container
# docker Start/stop/restart <container>

Run a container (including historical container) again
#docker start [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), provided that the Docker PS command has an active ID for this container
#docker Attach [container_id]

Start a container and enter interactive mode (equivalent to start, in attach), provided that the Docker PS command has the active ID of this container exists
#docker start-i <container>

Note: When a container is created successfully and enters the container, do not manually ctrl+d exit. If the window is closed, as long as it is in a running state, you can use attach to enter
[[email protected] ~]# Docker PS
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b4c27e360614 CentOS "/bin/bash", seconds ago up, seconds Lastapp_container
b9891bcdfed0 CentOS "/bin/bash" about a minute ago up about a minute App_container
Eaf66f1e43ab CentOS "/sbin/init" 2 hours ago up 2 hours 0.0.0.0:8888->8080/tcp Hungry_khorana
[email protected] ~]# Docker attach b4c27e360614
[Email protected]/]#

[email protected] ~]# Docker attach b9891bcdfed0
[Email protected]/]#

since eaf66f1e43ab this container will be dbus and other services to start up, its way of entry is different from other . Reference: http://www.cnblogs.com/kevingrace/p/6234600.html
[email protected] ~]# Docker exec-it Eaf66f1e43ab/bin/bash
[Email protected]/]#

[[email protected] ~]# Docker start-i App_container//press CTRL + C or ENTER.
[Email protected]/]#

Attention:
When the Docker attach is viewed again, exited (0) is gone, which means that the container has changed from a terminated state to a running state.
Once the command executes successfully, it will find that it has entered the container, and the previous operation's file still exists.
If the command does not respond after execution, click Enter again.

Docker attach that is to switch the background container to the foreground

Using image to create container and enter interactive mode, login shell is/bin/bash
#docker run-i-T <image>/bin/bash

Map the HOST port to the container to facilitate external access to the intra-container service, Host_port can be omitted, omitting the container_port mapping to a dynamic port.
#docker run-i-t-p

Attention:
Use start to start a container that has already been created, and use Run to open a new container through the image.

Check for a specific container
Check that a particular container can use the Docker inspect command followed by the container's name or unique ID.
# docker Inspect [OPTIONS] container| image| TASK [container| image| TASK ...]
Docker Auto-created container names are also inconvenient to remember, but we can use the--name parameter to specify a name for the container when it is run, and the command format is Docker run--name=<yourname>.
[email protected] ~]# Docker inspect App_container

Viewing the daemon container using the logs command
You can view the run log of a container by using the Docker Logs command, where the--tail option specifies to view the last few logs, while the-t option can append timestamps to the log entries. Use the-F option to track the output of the log until it is manually stopped.
# docker logs [OPTIONS] CONTAINER
[email protected] ~]# Docker logs App_container

View processes within a running container
# docker Top CONTAINER [PS OPTIONS]
[email protected] ~]# Docker logs App_container

Start a new process within a running container
While Docker encourages us to run only one service in a container, when we need to monitor, maintain, and manage a running container, we often need to start a new process for a running container.
# docker exec [OPTIONS] CONTAINER COMMAND [ARG ...]
This command is very similar to Docker run, and can be used with parameters such as-I,-t, and-D.
[email protected] ~]# Docker exec-i-T App_container/bin/bash

-i:–interactive using interactive creation of containers
-t:–tty provides terminals for containers

View root Password
Ocker The root user's password at the start of the container is randomly assigned. Thus, the root user's password for the container can be obtained in this way.
#docker Logs 5817938c3f6e 2>&1 | grep ' User: ' | Tail-n1
--------------------------------------------------------------------------------------------------------------- -----------------------

Deploying Docker Records under Linux (1)-volume using

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.