Home > Net >  How to mount nginx.conf to container in Docker Jenkins?
How to mount nginx.conf to container in Docker Jenkins?

Time:04-26

My Nginx in docker-compose.yml:

...
nginx:
  image: nginx:1.19.2-alpine
  restart: always
  hostname: nginx
  ports:
    - "9000:9000"
    - "9001:9001"
  depends_on:
    - minio
  volumes:
    - ./nginx.conf:/etc/nginx/nginx.conf:ro
  container_name: nginx
...

I use docker compose up -d in terminal and it works fine.

However, when I use docker compose up -d in Jenkins container, it failed to create Nginx container with this error:

ERROR: for nginx  Cannot start service nginx: failed to create shim: OCI runtime create failed:
container_linux.go:380: starting container process caused: process_linux.go:545: 
container init caused: rootfs_linux.go:75: mounting 
"/var/jenkins_home/workspace/workspace/nginx.conf" to rootfs at "/etc/nginx/nginx.conf" caused: 
mount through procfd: not a directory: unknown: Are you trying to mount a directory onto a file 
(or vice-versa)? Check if the specified host path exists and is the expected type

Does the error mean Docker want to mount the file inside Jenkins's volume so there's no nginx.conf to mount?

How can I mount my nginx.conf to my Nginx container?

Thanks in advance.

CodePudding user response:

It looks you're executing docker-compose up from a location such your relative path ./nginx.conf is not correct.

This error is typical when docker-compose cannot find source to mount bind-volume.

Assure you're in the correct docker-compose context or try with absolute path instead of ./nginx.conf

  • Related