this post was submitted on 16 Feb 2024
5 points (85.7% liked)

Docker

1105 readers
1 users here now

founded 1 year ago
MODERATORS
 

Is it possible to create a volume that is a file, not a directory?

I am trying to make a simple structured nginx instance with docker. Using this command below to create the container...

docker container create -v ./nginx.conf:/etc/nginx/conf.d/nginx.conf -v .:/app/ -p 80:80 docker.io/nginx

And this is the file structure of it...

- www
-------------- public
---------------------------- index.html
- nginx.conf

And this is the nginx.conf

server {
    server_name localhost;
    listen 80;
    
    root /app/www/public;

    index index.html index.htm;
    autoindex on;
}

However the index.html will not work when I go to the localhost.

When I change the docker command to this it does work however, but this will also mirror all of the files and folder from my file structure into the containers /etc/nginx/conf.d/ directory

docker container create -v .:/etc/nginx/conf.d/ -v .:/app/ -p 80:80 docker.io/nginx
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 3 points 9 months ago (2 children)

Use the absolute path to the file instead of a relative path.

[–] RandomDevOpsDude 1 points 9 months ago (1 children)

best way:

$(pwd)/ngnix.conf:<container path>

[–] [email protected] 1 points 9 months ago

When I change the path to this...

docker container create --name nginx -v $(pwd)/nginx.conf:/etc/nginx/conf.d/nginx.conf -v $(pwd):/app/ -p 80:80 docker.io/nginx

It does not seem to make a difference since when I go to localhost in my browser, I am still greeted with the "Welcome to nginx!" page.