In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Docker data management
In Docker, in order to easily view the data generated in the container or share the data in multiple containers, the data management operation of the container is involved.
There are only two ways to manage data in Docker containers: data volumes (Data Volumes) and data volume containers (Data Volumes Containers)
Data volume
The data volume is a special directory for the container, which is located in the container. You can mount the directory of the host to the data volume. The modification of the data volume is immediately visible, and updating the data will not affect the image. Thus, the data can be migrated between the host and the container.
1. Create a data volume
Use the-v option in the docker run command to create data volumes within the container. Use the-v option multiple times to create multiple data volumes. Use the-- name option to create a good custom name for the container.
Example:
Docker pull centos # download Image
# / data1 in the host directory / var/www mount container
Docker run-v / var/www:/data1-- name web1-it centos / bin/bash
[root@63031797b41f /] # cd / data1/
[root@63031797b41f data1] # touch test
[root@63031797b41f data1] # exit
# return to the host to view
[root@localhost ~] # ls / var/www/
two。 Data volume container
If you need to share some data between containers, the easiest way is to use a data volume container. A data volume container is an ordinary container that provides data volumes for mounting use by other containers.
How to use it: first, you need to create a container as a data volume container. Later, use-- volumes-from to mount the data in the data volume container when other containers are created.
Example:
# create 2 data volumes / data1,/data2, and data volume container web200
Docker run-- name web200-v / data1-v / data2-it centos / bin/bash
Exit # exit Container
# Mount the new container db1 to the data volume container web200
Docker run-it-volumes-from web200-name db1 centos / bin/bash
Mkdir / data1/test2 # create a directory test2 in the container db1
Exit # exit Container
Docker start web200 # start the data volume container
Docker exec-it web200 / bin/bash # enters the data volume container
[root@065387b882cb /] # ls / data1/ # you can see the new container db1 new directory in the data volume container web200
Test2
Port mapping
Docker provides a port mapping mechanism to provide services in the container to external network access, which essentially maps the port of the host to the container, so that the port of the host can access the services in the container.
Example:
Docker pull nginx # download Image
Docker run-d-P nginx # run Mirror-P (uppercase) random mapping port
Web page validation:
Or:
Docker run-d-p 81:80 nginx # specify mapped port 81
Docker ps-a
Web page validation:
Interconnection between containers 1. Create a source container
Docker run-P-- name web1-itd nginx / bin/bash # create and run a container named web1, and port numbers are automatically mapped
two。 Create an accept container
Docker run-P-name web2-link web1:web1-itd nginx / bin/bash # create and run the container named web2, link to web1 and communicate with it
3. Test container interconnection
Enter web2 container ping source container
Docker exec-it 9ee4fdb533ac / bin/bash
Ping web1
If the following problems occur:
It can be solved as follows:
Apt-get update
Apt install iputils-ping
Try ping web1 again:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.