Skip to content

Commit

Permalink
Add more pages
Browse files Browse the repository at this point in the history
  • Loading branch information
maricaantonacci committed Jun 13, 2021
1 parent 894dcff commit d3be5c7
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
Binary file added docs/container/images/nginx_volume.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/container/images/nginx_volume_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/container/images/nginx_volume_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/container/images/nginx_volume_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/container/images/volume_types.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions docs/container/volume_plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
Docker Engine volume plugins enable Engine deployments to be integrated with external storage systems such as NFS, Ceph, Openstack Cinder, Amazon EBS, and enable data volumes to persist beyond the lifetime of a single Docker host.

This section will show an example using the [Netshare](http://netshare.containx.io/) docker volume plugin to mount NFS shares inside our container.

!!! note
Netshare is a Docker volume plugin for NFS 3/4, EFS and CIFS/SMB.
We will show its usage with NFS as an example. However consider that you can attach NFS volumes to docker containers using the `local` driver as well since docker provides natively the support for NFS. For example:
```bash
# docker volume create --driver local --opt type=nfs --opt o=addr=<nfs server ip>,rw --opt device=:<export nfs path> <volume name>
```

The plugin has been installed following the instructions provided in the [docs](http://netshare.containx.io/docs/getting-started).

The NFS server has been installed on the machine with IP `192.168.28.53` and configured to export the path `/mnt/nfs_share/nginx`:

```bash
Export list for 192.168.28.53:
/mnt/nfs_share/nginx 192.168.28.151
```

You can check that the docker plugin service is up and running on the docker host:

```bash
sudo systemctl status docker-volume-netshare
```

```bash
● docker-volume-netshare.service - LSB: Init for docker-volume-netshare
Loaded: loaded (/etc/init.d/docker-volume-netshare; generated)
Active: active (running) since Sun 2021-06-13 13:23:58 UTC; 1h 6min ago
Docs: man:systemd-sysv-generator(8)
Process: 716471 ExecStart=/etc/init.d/docker-volume-netshare start (code=exited, status=0/SUCCESS)
Tasks: 5 (limit: 4683)
Memory: 6.3M
CGroup: /system.slice/docker-volume-netshare.service
└─716480 /usr/bin/docker-volume-netshare nfs

Jun 13 13:23:58 tutorvm-1 systemd[1]: Starting LSB: Init for docker-volume-netshare...
Jun 13 13:23:58 tutorvm-1 docker-volume-netshare[716471]: * Starting Docker-Volume-Netshare: docker-volume-netshare
Jun 13 13:23:58 tutorvm-1 docker-volume-netshare[716471]: ...done.
Jun 13 13:23:58 tutorvm-1 systemd[1]: Started LSB: Init for docker-volume-netshare.
```

Launch the `nginx` container with an NFS docker volume:

```bash
docker run -d -p 8081:80 --name nginx_nfs --volume-driver=nfs -v 192.168.28.53/mnt/nfs_share/nginx:/usr/share/nginx/html nginx
```

Check the volume list:

```bash
docker volume ls
DRIVER VOLUME NAME
nfs 192.168.28.53/mnt/nfs_share/nginx
```

Inspect the volume:

```bash
docker inspect 192.168.28.53/mnt/nfs_share/nginx
[
{
"CreatedAt": "0001-01-01T00:00:00Z",
"Driver": "nfs",
"Labels": null,
"Mountpoint": "/var/lib/docker-volumes/netshare/nfs/192.168.28.53/mnt/nfs_share/nginx",
"Name": "192.168.28.53/mnt/nfs_share/nginx",
"Options": null,
"Scope": "local"
}
]
```

The plugin has automatically mounted the NFS volume on your docker host...look at the mounts:

```bash
sudo mount | grep nginx
192.168.28.53:/mnt/nfs_share/nginx on /var/lib/docker-volumes/netshare/nfs/192.168.28.53/mnt/nfs_share/nginx type nfs4 (rw,relatime,vers=4.2,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.28.151,local_lock=none,addr=192.168.28.53)
```

Now connect to the deployed service (`nginx`) on port `8081`:

![](images/nginx_volume_4.png)
4 changes: 4 additions & 0 deletions docs/container/volume_summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@



![](images/volume_types.png){: style="width:auto;border:1px solid;border-color:#346ed1"}
99 changes: 98 additions & 1 deletion docs/container/volumes.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,105 @@ docker container rm -f nginx3

Recreate it with the volume mounted:
```bash
docker container run -d -p 8080:80 --name nginx3 --mount source=myvol,destination=/usr/share/nginx/html nginx
docker container run -d -p 8080:80 --name nginx3 --mount type=volume,source=myvol,destination=/usr/share/nginx/html nginx
```

!!! note
- if we didn’t create the volume earlier docker will create it for us with the name given in source field of `--mount` parameter
- volumes by default will not be deleted while we removing the container
- if the container has got in `target` directory any files, this files will be copied into the volume

Enter the container and modify the welcome page:

```bash
docker exec -it nginx3 bash
```

Once inside the container, run the following command:

```bash
echo "I've changed the content of this file in the docker volume" > /usr/share/nginx/html/index.html
```

![](images/nginx_volume.png)

Let' stop and remove this container and create a new one with the same command:

```bash
docker rm -f nginx3
```
then
```bash
docker container run -d -p 8080:80 --name nginx3 --mount type=volume,source=myvol,destination=/usr/share/nginx/html nginx
```

If we load the page again we will still see the html file that we edited in the volume.

### Using bind mounts

!!! note
- if we didn’t create a directory on docker host earlier docker will not create it for us with `--mount` parameter, auto-creating is available only in older `--volume`
- bind mounts by default will not be deleted while removing the container
- if the container has got in `target` directory any files, this files will **NOT** be copied into bind mount directory, bind directory will cover any files in a target container directory

Try the following command:

```bash
docker container run -d -p 8088:80 --name nginx4 --mount type=bind,source=/tmp/nginx,destination=/usr/share/nginx/html nginx
```

You will get an error since the path `/tmp/nginx` does not exist:
```
docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /tmp/nginx.
See 'docker run --help'.
```

Let's create the directory on the host:

```bash
mkdir /tmp/nginx
```

Now re-run the command for creating the container:

```bash
docker container run -d -p 8088:80 --name nginx4 --mount type=bind,source=/tmp/nginx,destination=/usr/share/nginx/html nginx
```

If you inspect the container you will see the bind-mount:

```bash
docker container inspect nginx4
```

```bash
...
"Mounts": [
{
"Type": "bind",
"Source": "/tmp/nginx",
"Target": "/usr/share/nginx/html"
}
],
...
```

Connect to port `8088` on the host IP to see the result:

![](images/nginx_volume_2.png)

As you can see we get an error message from nginx as the bind-mount has overwritten the content of `/usr/share/nginx/html` (Remember that the behaviour with docker volumes is different, any file inside the container is copied in the volume)

Let's create the `index.html` file in the host path `/tmp/nginx`:

```bash
echo "I've changed the content of this file on the host" > /tmp/nginx/index.html
```

Then reload the page in the browser:

![](images/nginx_volume_3.png)

!!! question
As done before, try to remove the container and recreate it with the same bind-mount...what happens?

2 changes: 1 addition & 1 deletion docs/intro/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Source: [https://twitter.com/pierrecdn/status/620587662928424960](https://twitte
```
- **docker kill** command will kill all the processes in the container: the main process will be sent a SIGKILL or any signal specified with option `–signal`.
```bash
docker unpause <container name>
docker kill <container name>
```

## Docker command syntax
Expand Down
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ nav:
- Bridge mode and port mapping: 'container/networking.md'
- Persistent data:
- Docker volumes and bind-mounts: 'container/volumes.md'
- Docker volume plugins - an example: 'container/volume_plugin.md'
- Summary: 'container/volume_summary.md'


copyright: Copyright &copy; 2021 INFN

0 comments on commit d3be5c7

Please sign in to comment.