In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
1. Brief introduction to Docker data management
Docker provides three different ways to mount data from the host to the container: volumes,bind mounts and tmpfs.
1.Volumes:Docker manages part of the host file system (/ var/lib/docker/volumes).
2.bind mounts: it can be mounted anywhere on the host system.
3.tmpfs: mounts and stores in the memory of the host system and does not write to the host text system.
Second, manage volume volumes
1. Manage volume volumes
# display Volume
[root@docker sky9890] # docker volume ls
DRIVER VOLUME NAME
Local 0b37cdeff2004e6f6293ba0175df953e93a0244c945dd030a27c9c2d70015473
……
# create a volume
[root@docker sky9890] # docker volume create nginx-vol
Nginx-vol
[root@docker sky9890] # docker volume ls
Local nginx-vol
[root@docker sky9890] # docker volume inspect nginx-vol
[
{
"Driver": "local"
"Labels": {}
"Mountpoint": "/ var/lib/docker/volumes/nginx-vol/_data"
"Name": "nginx-vol"
"Options": {}
"Scope": "local"
}
]
two。 Create a container with a volume:
[root@docker sky9890] #
Docker run-d-- name=nginx-test-- mount src=nginx-vol,dst=/usr/share/nginx/html nginx
Unknown flag:-- mount
[root@docker sky9890] # docker run-d-it-- name=nginx-001-v nginx-vol:/usr/share/nginx/html nginx
2c3e14431a622a4c9af303596853cc5b59696c42c4da5e264dfc190e7f5f4c71
# execute nginx-001 container
[root@docker sky9890] # docker exec-it nginx-001 bash
Root@2c3e14431a62:/#
Root@2c3e14431a62:/# cd / usr/share/nginx/html/
Root@2c3e14431a62:/usr/share/nginx/html# ls
50x.html index.html
# create a test.html file in the container
Root@2c3e14431a62:/usr/share/nginx/html# touch test.html
Root@2c3e14431a62:/usr/share/nginx/html# ls
50x.html index.html test.html
Root@2c3e14431a62:/usr/share/nginx/html# vim test.html
Welcome to learn Docker!
# synchronize the files created in the container in the volumes data volume
[root@docker sky9890] # cd / var/lib/docker/volumes/nginx-vol/_data/
[root@docker _ data] # ls
50x.html index.html
[root@docker _ data] # ls
50x.html index.html test.html
# Delete all containers
# Docker rm-f $(docker ps-Q-a)
# Docker ps-a
# create a nginx-003 container
[root@docker _ data] # docker run-d-it-- name=nginx-003-p 8081 docker run 80-v nginx-vol:/usr/share/nginx/html nginx
7aacbe13f3817e54965e0c7d48969d465665a28e4413b418066385805a08b60f
# stop the nginx-test container
[root@docker _ data] # docker container stop nginx-test
Nginx-test
# Delete nginx-test container
[root@docker _ data] # docker container rm nginx-test
Nginx-test
# unable to delete nginx-vol volume because it is still in use
[root@docker _ data] # docker volume rm nginx-vol
Error response from daemon: Unable to remove volume, volume still in use: remove nginx-vol: volume is in use-[2c3e14431a622a4c9af303596853cc5b59696c42c4da5e264dfc190e7f5f4c71, e64dab498554ee101b0157cbbf4fbe5d5295ec2519327c6afbe042e60222d618, 7aacbe13f3817e54965e0c7d48969d465665a28e4413b418066385805a08b60f]
Docker stop nginx-vol
Docker volume rm nginx-vol
Docker stop nginx-001
Docker stop nginx-002
Docker stop nginx-003
[root@docker _ data] # docker ps
# stop all containers and delete nginx-vol volumes
Summary:
1. If no volume is specified, it is automatically created.
two。 The coach suggests using-mount, which is more general. But an error is reported when using mount.
III. Bind Mounts
# delete all containers first
[root@docker sky9890] # docker rm-f $(docker ps-Q-a)
7aacbe13f381
E64dab498554
2c3e14431a62
01791c36ed28
.
Fe6672a1ba22
# create a volume
# method 1: the original directory must be created first, otherwise an error will be reported
[root@docker sky9890] # mkdir-p / app/wwwrott
[root@docker sky9890] #
Docker run-d-it-- name=nginx-test
-- mount type=bind,src=/app/wwwroot,dst=/usr/share/nginx/html nginx
Unknown flag:-- mount
# mount error report
Method 2:
[root@docker sky9890] # docker run-d-it-- name=nginx-test
-v / app/wwwroot:/usr/share/nginx/html nginx
Ee97dec7d52b310eb3d93f42e05f272e3f97e23b5c49625966310d86b834ab0d
# execution Container
[root@docker sky9890] # docker exec-it nginx-test bash
Root@ee97dec7d52b:/#
Root@ee97dec7d52b:/usr/share/nginx/html# ls
Root@ee97dec7d52b:/usr/share/nginx/html# ls
Index.html
Root@ee97dec7d52b:/usr/share/nginx/html# cat index.html
Welcome to learn Docker!
# create an index.html on the host machine and synchronize it to the specified directory of the container
[root@docker wwwroot] # pwd
/ app/wwwroot
[root@docker wwwroot] # ls
[root@docker wwwroot] # touch index.html
[root@docker wwwroot] # ls
Index.html
[root@docker wwwroot] # vim index.html
Welcome to learn Docker!
# verify binding
[root@docker wwwroot] # docker inspect nginx-test
# docker container stop nginx-test
# docker container rm nginx-test
Summary:
1. If the source file / directory does not exist, it will not be created automatically and an error will be thrown.
two。 If the mount directory is not an empty directory in the container, the existing contents of the directory are hidden.
four。 Problems in the process of creating a data volume container
The mount parameter used in creating a container using volume and Bind Mounts will report the following error:
Docker Unknown flag-mount
The reasons are as follows:
Docker run support for the-- mount option was only introduced in Docker 17.06. You are using Docker 1.13.1. You have two choices:
1. Update to Docker 17.06 or later if you can
2. Use the-v approach to bind mount the volume you require e.g. Docker run-v $(pwd): / home
Resolution step: upgrade the docker version
1. Find relevant software packages on the host
[root@docker /] # rpm-qa | grep docker
Docker-1.13.1-108.git4ef4b30.el7.centos.x86_64
Docker-client-1.13.1-108.git4ef4b30.el7.centos.x86_64
Docker-common-1.13.1-108.git4ef4b30.el7.centos.x86_64
two。 Uninstall software-related packages
[root@docker /] # yum remove docker-1.13.1-108.git4ef4b30.el7.centos.x86_64
Warning: / etc/sysconfig/docker-storage has been saved as / etc/sysconfig/docker-storage.rpmsave
Warning: / etc/docker/daemon.json has been saved as / etc/docker/daemon.json.rpmsave
[root@docker /] # yum remove docker-client-1.13.1-108.git4ef4b30.el7.centos.x86_64
[root@docker /] # ym remove docker-common-1.13.1-108.git4ef4b30.el7.centos.x86_64
[root@docker sky9890] # docker
Bash: docker: command not found
3. Upgrade to the latest version
[root@docker sky9890] # curl-fssl https://get.docker.com/ | sh
If you would like to use Docker as a non-root user, you should now consider
Adding your user to the "docker" group with something like:
Sudo usermod-aG docker your-user
Remember that you will have to log out and back in for this to take effect!
WARNING: Adding a user to the "docker" group will grant the ability to run
Containers which can be used to obtain root privileges on the
Docker host.
Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
For more information.
4. Restart Docker
# systemctl rstart docker
5. Set up boot boot
# systemctl enable docker
6. View docker version information
[root@docker sky9890] # docker version
Client: Docker Engine-Community
Version: 19.03.7
API version: 1.40
Go version: go1.12.17
Git commit: 7141c199a2
Built: Wed Mar 4 01:24:10 2020
OS/Arch: linux/amd64
Experimental: false
.
7. View container information
[root@docker sky9890] # docker info
Client:
.
Kernel Version: 3.10.0-862.11.6.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 983.3MiB
Name: docker
ID: E33X:T43J:BY3N:CFKG:6L7Q:XSGB:JZPA:GFNI:QHT5:LSAU:YDZW:BPAI
Docker Root Dir: / var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: IPv4 forwarding is disabled
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
8. View Mirror
[root@docker sky9890] # docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Sky9899 self 1302c27299d6 20 hours ago 1.22MB
Busybox v2 6e9545b1e2a2 20 hours ago 1.22MB
Tomcat latest 4e7840b49fad 6 days ago 529MB
Nginx latest a1523e859360 7 days ago 127MB
Python 3.5 0320ef7199ca 7 days ago 909MB
Mysql latest c8ad2be69a22 7 days ago 465MB
Php latest e66ae809d99a 7 days ago 405MB
Httpd latest c5a012f9cf45 7 days ago 165MB
Mongo latest bcef5fd2979d 12 days ago 386MB
Ubuntu latest 72300a873c2c 12 days ago 64.2MB
Centos latest 470671670cac 6 weeks ago 237MB
Busybox latest 6d5fcfe5ff17 2 months ago 1.22MB
Nginx 1.11 5766334bdaa0 2 years ago 183MB
Nginx 1.11 5766334bdaa0 2 years ago 183MB
Nginx v1 5766334bdaa0 2 years ago 183MB
WARNING: IPv4 forwarding is disabled
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
9. Solve the problem of alarm in the above three years
[root@docker sky9890] # vim / etc/sysctl.conf
Net.ipv4.ip_forward=1
Net.bridge.bridge-nf-call-ip6tables=1
Net.bridge.bridge-nf-call-iptables=1
[root@docker sky9890] # sysctl-p
10. Test mount
[root@docker sky9890] # docker run-d-it-name=nginx-test-mount type=bind,src=/app/wwwroot,dst=/usr/share/nginx/html nginx
Unable to find image 'nginx:latest' locally
Latest: Pulling from library/nginx
68ced04f60ab: Already exists
28252775b295: Pull complete
A616aa3b0bf2: Pull complete
Digest: sha256:2539d4344dd18e1df02be842ffc435f8e1f699cfc55516e2cf2cb16b7a9aea0b
Status: Downloaded newer image for nginx:latest
Docker: Error response from daemon: Conflict. The container name "/ nginx-test" is already in use by container "ee97dec7d52b310eb3d93f42e05f272e3f97e23b5c49625966310d86b834ab0d". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run-- help'.
[root@docker sky9890] # docker run-d-it-name=nginx-mount type=bind,src=/app/wwwroot,dst=/usr/share/nginx/html nginx
15ef64d51e113d571b0cb6fb89d3b891bcba826f4cc2ae2e3ad584294274aa9d
[root@docker sky9890] # docker start nginx
Nginx
[root@docker sky9890] # docker exec-it nginx bash
Root@15ef64d51e11:/#
Root@15ef64d51e11:/# ls / usr/share/nginx/html/test.html
/ usr/share/nginx/html/test.html
Root@15ef64d51e11:/# cat / usr/share/nginx/html/test.html
Sovle Docker Unknown flag-mount
# create a file on the dormitory machine and synchronize it to the directory specified by the container
[root@docker wwwroot] # vim test.html
Sovle Docker Unknown flag-mount
# recreate a container and refer to a port
[root@docker sky9890] # docker run-d-it-- name=nginx01-p 8080 it 80-- mount type=bind,src=/app/wwwroot,dst=/usr/share/nginx/html nginx
6cc7f85a4cd1cc0fb23f2a60a1ae74bec2812d7a607ce7800f9f2db97ba8a052
# successful test
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.