what is the absolute path of a folder in docker? - docker

I want to run an already existing app on docker. The app interacts with some files on a folder. So i am trying to hook up a volume.
Here is the docker-compose:
test:
container_name: test
volumes:
- C:\test\:\test\
build: .
When i hook into the docker image i can see that the folder is created on the root folder. Now i need to write the correct path to that folder into the application settings.
Before it was something like this:
"test": {
"Path": "C:\\test\\"
}
But i dont know how to get the absolute path of my folder from inside docker, so my app can understand where to search for it.
Thank you
EDIT: it looks like the problem was on my side: the way i defined the volumes created a folder with the name "\test\" ... doing C:\test:/test/ instead did the trick

If you’re building your own Docker image, you control the filesystem layout entirely. For Linux-based images it’s common to follow the FHS standard (I think the standard MySQL image stores its data in /var/lib/mysql) but it’s also common enough to just store data in subdirectories of the root directory (/data or /config or what not).
If you have a setup like this, your image should pick a path. If the only thing in the configuration is the location of that directory, it’s fine to hard-code it in the image. However you document your image (even if it’s just a standard docker-compose.yml file) mention that you have this fixed path; it doesn’t need to match the host path (if any) on any particular system.

Related

InteliJ does not recognize one of two docker compose file as compose file

I've had this problem for about a year and a half, but i haven't done anything about it up until now.
My work colleague doesn't have this problem on his PC, when he looks at his compose files.
So it seems that i have done something at some point to have my IDEA behave this way.
This is how my folder structure looks. Notice how on the develop compose file icon there is no "C" to signify that it is a "Compose" file.
This is how the inside of my develop compose file looks.
And this is how the the inside of my master compose file looks like.
I await your guidance fellow humans.
EDIT:
Here is the requested screenshot of my file type settings.
You need to remove docker-compose-develop.yml from the Dockerfile file type.
Yaml docker-compose files are not related to Dockerfile and will have DC icon when IDE detects version and services in the file.

Docker File Location for Asp.Net core

I am running Docker in Windows, using Linux containers.
I have an asp.net core hello-world app that writes a text file:
var path = Path.Combine(
Directory.GetCurrentDirectory(), "text.txt");
System.IO.File.WriteAllText(path, "text");
Directory.GetCurrentDirectory() comes back as "/app"
In my docker-compose I map /app to /usr/xxxxx
volumes:
- /app:/usr/xxxxx
My question is: Where on my Windows file system is the /usr/xxxxx ? I want to back it up so that it stays after containers are removed.
Volumes (actually bind-mounts) use the format host-path:container-path.
It looks like you put it in the wrong order in the docker-compose file.
Also, as there is no folder called /usr/xxx on windows, just use a path that exists instead.
For example, you can create a directory called "backup" inside the directory with the docker-compose file, and then modify the docker-compose file like so
volumes:
- "./backup:/app"
In the standard Dockerfile that Visual Studio generates, your application dll's are copied into /app. Therefore, it might be a bad choice to use /app. I'm actually not sure what happens if the bind-mount directory already exists with different data inside the container. But you could just write the file to another directory and use that instead.

Docker-compose mount folder

Hi I have multiple folders that I wish to mount. this is the scenario:
On my host:
path\to\mount\HostFolder\folder_*
On my container:
\path\to\mount\ContainerFolder\
* is a number
I want to mount all folder_* to ContainerFolder\
ContainerFolder already have some folders inside so I must not mount HostFolder to ContainerFolder to save them.
I wish to use regex but volume keyword doesn't seems to support it, any suggestions how to manage that?
My only idea right now is script to write for me the docker-compose.
My suggestion would be to seriously reconsider the assumption that you need the current directory structure. (Of course, this may be impossible, I know.)
If you can change the directory structure at all, you can try restructuring the folders like this:
ContainerFolder
folders
folder_1
folder_2
In this way, you can mount the HostFolder into a subdirectory of ContainerFolder without overwriting the contents of ContainerFolder itself.

ADD command with network path in Windows Containers Dockerfiles

I'm creating some Windows Container images that I need but the source file I want to ADD are in a network share \\myserver\myshare\here.
I've tried in any possible way but I always get the message error The system cannot find the path specified.
Is it because I have not yet found the right way to set it or is it that it is just not possible?
From the Docker site:
Multiple resource may be specified but if they are files or directories then they must be relative to the source directory that is being built (the context of the build).
Is that why I can't accomplish what I need?
Full error message: GetFileAttributesEx \\myserver\myshare\here\: The system cannot find the path specified.
Whatever you ADD or COPY must be in the docker build context.
When you do this:
docker build .
That directory param (the . in the example) is the context that is copied and sent to the Docker daemon. Then the docker daemon use those files to COPY or ADD. It won't use any file that is not in that context.
That is the issue that you are experiencing. I'm not sure how you can solve it anything than copying the files from \\myserver to your build directory.
ADD is capable of download files by providing an URL (should investigate if it supports Windows' shares)

How to map all containing folders using volume path docker

I'm new to Docker so let me know whether I should be doing something completely different, but here goes..
I'd like to create a volume within an nginx container which maps all sites-enabled configuration files to the location on the container. The catch is, these files are scattered across multiple folders which can be named at random. But wait! I can tell you for certain that the .conf file will always be in a specific folder only 1 level deep (because that's how I prefer the layout to be). Here's a basic layout explaining what I mean:
- images/
- nginx/
- docker-compose.yml
- sites/
- site_a/
- vhost/
site_a.conf
- site_b/
- vhost/
site_b.conf
I have tried to do this when declaring the volumes for nginx:
- ../sites/*/vhost/:/etc/nginx/sites-enabled
Yet I get the following error:
ERROR: for nginx Cannot start service nginx: mkdir /c/Users/Yates/Documents/docker/sites/*: protocol error
I kind of get the error, yet I can't find anything telling me how accomplish what I eventually want. Any help would be much appreciated.
Pretty sure you can't do this.
What you could do is symlink copy all the .conf files into a single directory on the host and use that as your volume mount point. Or just mount the sites/ root directory.
This is a conceptional question and your concept is very fragile and will lead to issues most probably.
What you are doing wrong is:
the configuration for the httpd server is kept inside the sites data/configuration structure or at least its nested inside
You are trying to configure a dynamic amount of 'services' sites using a static+nested folder. You are mixing up "configuration" and data. Try to put your configuration into something like consul/etcd/zookeeper and generate configuration usint tiller ( confd/consul-template)
If you to force it, you can:
Way a)
Mount the volume holding the sites folder in nginx, read only ( however this volume is called )
Then you runn an entrypoint script in the nginx container, some find expression to traverse your "sites" folder, find any site, use the vhost folder and create a symlink from there to /etc/nginx/sites-enabled
You need to also think about deletions, so pick a good namespaces for the symlinks, like mysite.automated.conf and before the entrypoint creates the symlinks, you run rm /etc/nginx/sites-enabled/*automated.conf to flush the potentially outdated/deleted ones. You can do it the update way also, but thats for more complicated..
way b)
If you can, change the structure of sites in general, extrac all "vhosts" into one folder, lets say you will have
sites/vhosts/*.sites.conf
sites/data/siteA/
sites/data/siteA/
and then mount the volume read-only on nginx and symlink sites/vhosts to /etc/nginx/site-enabled ( the folder itself )

Resources