In general, Docker containers do not work for a long time. In fact, these containers are temporary and will run until the command issued in the container is completed. All data generated in the container will only be available in the container when executed. In this article, we will teach you how to share data between a Docker container and a host.
Docker volumes can be used to share files between host systems and docker containers. For example, if you plan to use the official Docker Nginx image and keep a permanent copy of the Nginx report files for analysis, by default the Docker Nginx image will go to the var / log / nginx folder and the Docker Nginx container.
How to connect container, docker and host?
To do this, you need an Ubuntu 18.04 server that has the following prerequisites:
Note: Be sure to note that even if the prerequisites provide instructions for installing Docker on Ubuntu 18.04, Docker data volume commands must run on other operating systems while Docker is installed.
The following command creates a directory called nginxlogs in your current user’s root directory and moves it to / var / log / nginx in the container:
$ docker run --name=nginx -d -v ~/nginxlogs:/var/log/nginx -p 5000:80 nginx
We will now take a closer look at this command:
Docker team in Ubuntu 18.04
Note: The -v flag is very flexible. This allows you to name or associate the volume with a slight change in settings.
If the first argument starts with / or ~ /, you create Bindmount.
-v / path: / path / in / the container installs the host directory; / path در / path / in / container
-v path: / path / in / container also creates a volume called path without connection to the host.
We already have a copy of Nginx running in the Docker container of our machine or host and the 5000 port of our host machine is written directly to this copy of the 80 Nginx port.
In the web browser of your choice, load the address using your IP or hostname, and the port number is http: // your_server_ip: 5000.
Create an nginx container
It is interesting to know that if you look at the ~ / nginxlogs list in the host, you will see access.log created by the nginx container. This will indicate your request:
$ cat ~/nginxlogs/access.log
This command should look like this:
Exit
۲۰۳٫۰٫۱۱۳٫۰ - - [۱۱/Jul/2018:00:59:11 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36" "-"
If you make changes to the / nginxlogs folder, you can see them from the Docker container.
In this article we will teach you how to share data between container, docker and host. With this tutorial, you can easily create a Docker data volume to share information between the container and the host’s file system.
Docker containers are temporary and will run until the command issued in the container is completed.
You can use Docker volumes to share files between host systems and Docker containers.
To Ubuntu server 18.04
{“@context”: “https://schema.org”, “@type”: “FAQPage”, “mainEntity”: [{
“@type”: “Question”,
“name”: “کانتینرهای داکر تا چه زمانی کار میکنند؟”,
“acceptedAnswer”: {
“@type”: “Answer”,
“text”: “کانتینرهای داکر حالت موقتی دارند و تا زمانی کار خواهند کرد که فرمان صادرشده در کانتینر تکمیل شود.”
}
},{
“@type”: “Question”,
“name”: “چگونه میتوانیم فایلها را بین سیستم هاست و کانتینر داکر بهاشتراک بگذاریم؟”,
“acceptedAnswer”: {
“@type”: “Answer”,
“text”: “از حجمهای Docker میتوانید برای اشتراکگذاری فایلها بین سیستم هاست و کانتینر داکر استفاده کنید.”
}
},{
“@type”: “Question”,
“name”: “استفاده از این روش برای اشتراکگذاری فایلها بین سیستم هاست و کانتینر داکر به چه ابزاری نیاز دارد؟”,
“acceptedAnswer”: {
“@type”: “Answer”,
“text”: “به سرور اوبونتو ۱۸٫۰۴”
}
}]
}
A lesson on sharing data between a Docker container and a host for the first time in Parsupak. appear.