Sharing Volumes Between Containers Rumi, July 28, 2020 There are many situations where it is useful to share a Docker volume between containers, and several ways to accomplish this goal. Sharing a Volume on the Host If you create a volume on the host machine, it can be used by multiple different containers at once. This allows you to share data between containers and the host. For this example we will create a directory on the host, and use that directory as a shared volume between two containers. Begin by creating a directory to use as a Docker volume with the command: sudo mkdir /webdata Create a small test file in this directory with the command: sudo echo "Hello from the host." >> /webdata/host-hello.txt Next, launch a container named sql-database from the official PostgreSQL image, and map /webdata on the host to /data on the container with the command: sudo docker run -it --name sql-database -v /webdata:/data postgres /bin/bash Once you are at the new container’s command prompt verify that the shared volume is set up correctly with the command: ls /data You will see the host-hello.txt file which we created on the host. Let’s add a file to this shared volume with the command: echo "Hello from the sql-database container." >> /data/sql-hello.txt Detach from the container with Ctrl-p + Ctrl-q and return to the host machine’s command prompt. Now launch a container named webapp from the official PHP+Apache image, and map /webdata on the host to /var/www/html on the container. sudo docker run -it --name webapp -v /webdata:/var/www/html php:5.6-apache /bin/bash Once you are at the new container’s command prompt, verify that the shared volume is set up correctly with the command: ls /var/www/html You will see both the host-hello.txt file which we created on the host, and the sql-hello.txt file we created on the sql-database container. Let’s add a file from this container as well: echo "Hello from the webapp container." >> /var/www/html/webapp-hello.txt Detach from the container with Ctrl-p + Ctrl-q and return to the host machine’s command prompt. Once on the host machine, you will see all three files listed with the command: sudo ls /webdata Now that the two containers are sharing a directory which “lives” on the host, data can be transferred instantly between all three locations simply by moving it to that directory. Using a Container as a Shared Data Volume You can also set up a separate container as a shared data volume. To do this, first create the data container. Then, when you create the container that will be using that data container, add the following argument to the docker run command: --volumes-from [name or ID of data container] Note: This will work whether or not the target container is running. Docker volumes are never deleted, and persist even after the container has been stopped. For this example we will create a data container called data-storage which will serve as the data volume, and two other containers that share it as a storage volume. First, launch the data-storage container from the official CentOS 7 image: sudo docker run -it -v /shared-data --name data-storage centos /bin/bash Then add a small file to the /shared-data folder: echo "Hello from the data-storage container." >> /shared-data/data-storage-hello.txt Detach from the container with Ctrl-p + Ctrl-q and return to the host machine’s command prompt. Now launch the app container from the official Python image and mount the data-storage container as a volume: sudo docker run -it --name app --volumes-from data-storage python /bin/bash List the files in the shared volume with the command: ls /shared-data As you can see, the /shared-data folder has been mounted from the /shared-data folder on the data-storage container, and contains the data-storage-hello.txt file. Let’s add one from this container: echo "Hello from the app container." >> /shared-data/app-hello.txt Detach from the container with Ctrl-p + Ctrl-q and return to the host machine’s command prompt. Finally, launch the web container from the official Apache image and mount the data-storage container as a volume: sudo docker run -it --name web --volumes-from data-storage httpd /bin/bash List the files in the shared volume with the command: ls /shared-data You will see the files we created on the data-storage and app containers listed here. Src: https://www.ionos.com/community/server-cloud-infrastructure/docker/understanding-and-managing-docker-container-volumes/ Related Administrations Configurations (Linux) DockerDocker NFSDocker Volume
Add a New Disk in Linux- Partition and Format May 9, 2018 Partition the new disk using fdisk command Following command will list all detected hard disks: # fdisk -l | grep ‘^Disk’ Output: Disk /dev/sda: 251.0 GB, 251000193024 bytes Disk /dev/sdb: 251.0 GB, 251000193024 bytes A device name refers to the entire hard disk. For more information see Linux partition naming… Read More
Ubuntu 18.04: Disable Netplan switch back to networking /etc/network/interfaces February 24, 2020June 17, 2020 The following procedure works for Ubuntu 18.04 (Bionic Beaver) I. Reinstall the ifupdown package: # apt-get update # apt-get install ifupdown II. Configure your /etc/network/interfaces file with configuration stanzas such as: source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback allow-hotplug enp0s3 auto enp0s3 iface enp0s3 inet static address 192.168.1.133 netmask 255.255.255.0 broadcast 192.168.1.255… Read More
Setting up a PPPoE server on Linux CentOS 7 July 8, 2023 Method-1 Build PPPoE, success, I think the TM super simple, in CentOS is about 5 steps can be done 1, install PPPoE, after the installation is complete, there will be pppoe-server command Yum Install Rp-pppoe 2, after the installation is completed, will be in the/ETC/PPP directory generated pppoe-server-options files, the… Read More