Ominus
Ominus

Reputation: 5721

Mounting NFS shares inside docker container using shell script

I have an Ubuntu container running on a windows host. I have all of the nfs client packages installed. I can connect to my container and mount an nfs share.

The idea is it start the container run my script have it mount two shares and then run gunicorn.

docker-compose.yml
version: '2.1'

services:
  web:
  #  restart: always
    build: .
    expose:
      - "5000"
      - "80"
    ports:
      - "5000:80"

    #command: gunicorn -w 4 wsgi_mount:app -b 0.0.0.0:80 --timeout 500
    privileged: true
    command: /bin/bash /app/entrypoint.sh

entrypoint.sh
------------
mount --verbose -t nfs -o nolock -o nfsvers=3 server:/nfs/share /app/path_to_mount1
mount --verbose -t nfs -o nolock -o nfsvers=3 server:/nfs/share /app/path_to_mount2
gunicorn -w 4 wsgi_mount:app -b 0.0.0.0:80 --timeout 500

Output

does not existt point /app/path_to_mount1
 does not existt point /app/path_to_mount2
[2017-10-04 16:29:57 +0000] [41] [INFO] Starting gunicorn 19.7.1
[2017-10-04 16:29:57 +0000] [41] [INFO] Listening at: http://0.0.0.0:80 (41)
[2017-10-04 16:29:57 +0000] [41] [INFO] Using worker: sync
[2017-10-04 16:29:57 +0000] [46] [INFO] Booting worker with pid: 46
[2017-10-04 16:29:57 +0000] [49] [INFO] Booting worker with pid: 49
[2017-10-04 16:29:57 +0000] [50] [INFO] Booting worker with pid: 50
[2017-10-04 16:29:57 +0000] [53] [INFO] Booting worker with pid: 53

What i find really frustrating is if i just have it run gunicorn then attach to the container and copy past the line from the script in the container for each mount point it works.

If i run the script inside the container i get the same exact error

I know the privileges are right, i now NFS is setup correctly, and i can manually make it work in my container but if try and do it from a bash script inside the container running the exact same commands i get "does not existt point ..." BTW the existt is not a typo it displays that way in the console.

EDIT: The accepted answer worked perfectly but i just want to add here that if the path exists in the container already then it won't mount. Also want to add that changing the yml file if you define the mount in the docker-compose file will not recreate it if its bad you have to rm the volume first.

Upvotes: 0

Views: 3132

Answers (1)

herm
herm

Reputation: 16315

You can mount nfs vumes using the docker deamon. That way you don't need nfs supprt inside your container. I cant see a reason why to mount inside the container instead

$ docker volume create --driver local \ --opt type=nfs \ --opt o=addr=192.168.1.1,rw \ --opt device=:/path/to/dir \ foo

Upvotes: 1

Related Questions