I have some confusing moments with docker-compose volumes (In docker windows server (container)).
I wrote the next configuration
volumes:
- "C:/ProgramData/Docker/volumes/admin-stat-logs:C:/app/Logs"
and why it so necessary to write the full path to the volume?
if I write:
volumes:
- "admin-logs:C:/app/Logs"
it generates the error
ERROR: Named volume "admin-logs:C:/app/Logs:rw" is used in service "admin-stat-table" but no declaration was found in the volumes section.
why does it happen?
UPDATE
let me show what I mean(I made wrong explonation). In an image, we have a short announcement from the official documentation.
I write the same in my case:
volumes:
- admin-logs:C:/app/Logs
I create volume before by the terminal. When I start docker-compose up I get the next error
ERROR: Named volume "admin-stat-logs:C:/app/Logs:rw" is used in service "admin-stat-table" but no declaration was found in the volumes section.
I made a mistake in the first case, it's a simple mount to a folder, sorry for my misunderstanding.
volumes:
- "C:/ProgramData/Docker/volumes/admin-stat-logs:C:/app/Logs"
You don't need to use a full path. You can use a relative path to the location of your docker-compose.yml file.
When you write admin-logs:C:/app/Logs, you're telling docker-compose to use a volume named admin-logs. If you want to use a folder where you docker-compose is located, you can write ./admin-logs:C:/app/Logs.
If you plan to use a separated docker volume, you need to first define it in the docker-compose.yml. Here's an example covering both cases:
version: '3'
services:
mytest:
image: ubuntu:18.04
volumes:
- "mymnt:/mnt/volume"
- "./mymnt_on_host:/mnt/mounted_folder"
volumes:
mymnt:
You'll need a mymnt_on_host directory in the folder where the docker-compose.yml is located.
For more info about this topic, you can check the reference guide for the docker-compose.yml
UPDATE:
If you plan to use an already created volume in your docker-compose, you can use external: true in the volumes definition.
e.g.
version: '3'
services:
mytest:
image: ubuntu:18.04
volumes:
- "mymnt:/mnt/volume"
- "./mymnt_on_host:/mnt/mounted_folder"
volumes:
mymnt:
my_existing_volume:
external: true
Now if you start this, docker-compose won't try to generate my_existing_volume but it'll expect to find it already on the machine.
For more info check external reference.
Can you show your version value in the docker-compose.yml file. It should be version: '3' or version: '3.5'. Probably you have version: '2'
Related
Host: Centos 7
Docker version: 19.03.12, build 48a66213fe
Docker compose version: version 1.26.2, build eefe0d31
I am using the advice given here on specifying environment variables in the shell and then passing those into the compose file. So my docker-compose file looks like this:
version: '3.8'
services:
springboot:
image: <my image>
ports:
- "8445:8445"
depends_on:
- "database"
environment:
- SPRING_PROFILES_ACTIVE=dev
database:
image: "mongo"
Here's the error that I've run into:
ERROR: for 39b165c237b9_deploy_springboot_1 Cannot create container for service springboot: invalid volume specification: 'a9d7debde5ffcba2a023c12d5f1e822567e9b4047a1bda76efeefbfc80c1f622:app/data:rw': invalid mount config for type "volume": invalid mount path: 'app/data' mount path must be absolute
The corresponding Docker file does have a reference to VOLUME app/data, however that doesn't seem controversial.
If I take out the environment block, it seems to work fine (though the application starts without having the right config, but at least it doesn't error).
So what is the right way to pass on shell environment variables to the container?
EDIT
Thanks to #David Maze, it was indeed the VOLUME declaration in the original Docker file - nothing to do with docker-compose. Deleted it and it now works. Thanks!
there are 2 ways to specify directories in docker.
absolute path i.e. from the root e.g. /var/lib
relative path i.e. relative to the compose file e.g. ./app/data
Try replacing SPRING_PROFILES_ACTIVE=devby SPRING_PROFILES_ACTIVE: dev Instead, so replace = with : . And you should also add the volume to the docker-compose file:
version: "3.8"
services:
.
.
volumes:
- Path/to/your/volume
environment:
ENV_VAR1: Value1
ENV_VAR2: Value2
.
.
.
And according the error message, the path must be absolute.
Hi I have a Nifi docker container stopped and I want to update a property file.
Whenever I update a field, when I run docker-compose start it doesn't update the property file.
How can this be possible?
here is my docker compose:
version: "3.3"
services:
nifi:
image: apache/nifi
volumes:
- /home/ubuntu/nifi/conf:/opt/nifi/nifi-current/conf
ports:
- "8080:8080"
Thanks
We had this issue a while back as well. I believe using volumes essentially creates a symlink, and when the container starts up it overwrites anything in that folder.
Have you considered creating a multistage build? That was our solution:
Dockerfile:
FROM apache/nifi:1.9.2
ADD /path/to/your-props.properties /opt/nifi/nifi-current/conf
We then put the resulting image in our compose
I am using owncloud docker image to create my owncloud. The problem is it's storing the data inside the docker image. However, I want one of my driver ( I am using windows) to be used as data files.
volumes:
files:
driver: local
services:
owncloud:
volumes:
- files:/mnt/data
This is what part of the docker-compose files looks like, I tried changing files:/mnt/data to .:/mnt/data. However, I started getting error when I tried to run the docker-compose.
The right way is to use double quotes to expand . as the current directory:
version: '3'
services:
nginx:
image: nginx
volumes:
- ".:/path/inside/container/"
I have a few questions about Docker volumes. I have installed Docker and docker-compose on a fresh host running debian stretch. I managed to get a docker-compose file running for a simple nginx/php-fpm project, both containers mounted on the directory containing the source code. I wanted to try to create a single volume that would be shared across my containers but I have a few issue, and my understanding of the official documentation is not helping.
So this is an idea of what I'm trying to achieve :
Question 1 : Trying to create a volume from a dockerfile on a directory mounted from host
docker-compose.yml :
version: '3'
services:
php:
build:
context: .
dockerfile: php.dockerfile
volumes:
- ./host-project-directory:/project
php.dockerfile :
FROM php:7-fpm
VOLUME project
from my understanding, when running docker-compose we should have a volume created on host containing all files from /project from container. And /project from container should contain all files from ./host-project-directory from host.
If I ls the content of /project on container I can see the files from host, but using docker volume list, there are no volumes created on host, why ?
Question 2 : How to populate and use this volume from another container ?
version: '3'
services:
php:
build:
context: .
dockerfile: php.dockerfile
volumes:
- named-volume:/project
web:
image: nginx
links:
- php
volumes:
- named-volume:/project
volumes:
named-volume:
This should create a volume called 'named-volume' and bind it to /project directories on both containers php and web.
Now, how to populate this volume with content from ./host-project-directory ?
I've tried adding a dockerfile like
ADD ./host-project-directory /project
But nothing changed and the volume remained empty.
I'm sorry if this is due to my lack of experience using Docker but I can't figure out how to make this simple thing work.
Thank you for your time !
For the first question, I try a simple docker file like this:
FROM php:7-fpm
COPY ./project /project
And a docker-compose like this:
version: '3'
services:
php:
build: .
volumes:
- named-volume:/project
web:
image: nginx
links:
- php
volumes:
- named-volume:/project
volumes:
named-volume:
Since you create the volume on docker-compose you don't need to create that in the Dockerfile.
Running docker volume list, I'm able to see the volume created with a local driver. Making ls inside the folder I'm also able to see the file. It's important to note, that the file present in you local directory it's not the same that the file inside the container. So if you edit the files in the host this will not change the files in container. That's because you have your volume created in another path, probably at: /var/lib/docker/volumes/...
This happens because you map the volume to the path, but you not specifies where you want the volume. To do that just make your docker-compose like this:
version: '3'
services:
php:
build: .
volumes:
- ./project:/project
web:
image: nginx
links:
- php
volumes:
- ./project:/project
Making this I'm still able to see the volume with the volume list command but without a name.
So I don't know why you are not able to see the volume in the list.
For question 2:
Doing the example above I have the files inside the container that exists in my local "project" folder.
Please check that the path to the local folder is correct.
A bind mount is not the same thing as a volume. You're defining a named volume here, but wanting the functionality of a bind mount.
Try this
version: '3'
services:
php:
build:
context: .
dockerfile: php.dockerfile
volumes:
- ./host-project-directory:/project
web:
image: nginx
links:
- php
volumes:
- ./host-project-directory:/project
With v2 of docker-compose synthax, we were able to do something like this:
version: '2'
services:
app:
image: tianon/true
volumes:
- ../app:/var/www/app
nginx:
image: nginx
volumes_from:
- app
php:
image: php
volumes_from:
- app
In v3.2 volumes_from is now invalid option. The documentation is all for using new top-level volumes synthax, which is all the ways better.
I've read some comments on github, and the only solution that people propose is
version: '3.2'
services:
nginx:
image: nginx
volumes:
- app:/var/www/app
php:
image: php
volumes:
- app:/var/www/app
volumes:
app:
driver_opts:
type: none
device: ../app
o: bind
Which looks worse obviously, and it even doesn't work for me. It gives me an error: no such file or directory. So what else should I try? It seems like I can still use links instead of top-level volumes, but it's considered as legacy option in documentation. So how to do it right with new syntax?
EDIT:
Question has been identified as a possible duplicate, but I don't agree. See my comment bellow for explanation.
As the topic starter already mentions, volumes_from has been removed from the new docker-compose syntax, according to the documentation in favour of named volumes defined in the top level key volumes. The documentation also states the difference between volumes and bind mounts, one of which is who manages the contents:
By contrast, when you use a volume, a new directory is created within Docker’s storage directory on the host machine, and Docker manages that directory’s contents.
If this is the case, then it does not make sense to bind mount a host folder into a volume and let it be controlled by the host's file system and by Docker simultaneously.
If you still want to bind mount the same folder into two or more containers you could try something like:
version: '3.2'
services:
nginx:
image: nginx
volumes:
- type: bind
source: ../app
target: /var/www/app
php:
image: php
volumes:
- type: bind
source: ../app
target: /var/www/app