I have the following two docker compose files:
docker-compose.yml :
version: '2.3'
services:
# test11 service
test11:
build: test11/.
image: "test11"
and
docker-compose.yml (file inside the folder named test11 that contains Dockerfile and the following docker-compose ):
version: '2.3'
networks:
citrixhoneypot_local:
services:
# CitrixHoneypot service
test11:
build: .
container_name: test11
restart: always
networks:
- citrixhoneypot_local
ports:
- "443:443"
image: "test11:2006"
# read_only: true
volumes:
- test11:/opt/test11/logs
volumes:
test11:
driver:local
when i run docker-compose up --build for the first file, everything seems ok and the container build and i can run exec -it sh on it and get access.
but the problem is that the volume isn't made in the path
/var/lib/docker/volumes and i can't find it there.
also when i write in /opt/test11/logs from inside the docker container no file is made under /var/lib/docker/volumes .
I tried this with bind path too. same problem with that too.
Related
I am using docker-compose and here is my docker-compose.yaml file:
version: "3.7"
services:
node:
container_name: my-app
image: my-app
build:
context: ./my-app-directoty
dockerfile: Dockerfile
command: npm run dev
environment:
MONGO_URL: my-database
port: 3000
volumes:
- ./my-app-directory/src:/app/src
- ./my-app-directory/node_modules:/app/node_modules
ports:
- "3000:3000"
networks:
- my-app-network
depends_on:
- my-database
my-database:
container_name: my-database
image: mongo
ports:
- "27017:27017"
networks:
- my-app-network
networks:
my-app-network:
driver: bridge
I expect to find a clear and newly created database each time I run the following command:
docker-compose build
docker-compose up
But this is not the case. When I bring the containers up with docker-compose up, my database has the exact state of the last time I shut it down with docker-compose down command. And since I have not specified a volume prop in my-database object, is this normal behaviour? Does this mean that no other action to persisting database state is required? And can I use this in production if I ever choose to use docker-compose?
The mongo image define the following volumes:
/data/configdb
/data/db
So docker-volume will create and use a unamed volume for data/db.
If you want to have a new one, use:
docker-compose down -v
docker-compose up -d --build
Or use a mount point mounted on the volume location like:
volumes:
- ./db:/data/db:rw
And drop your local db directories when you want to start over.
Im trying to share data between a few containers and the host using docker-compose. I have a docker-compose.yml file that looks like this:
version: '3'
services:
base:
container_name: base
build:
context: .
dockerfile: BaseDockerfile
volumes:
- dependencies:/volumes/dependencies
romee:
container_name: romee
build:
context: .
dockerfile: RomeeDockerfile
environment:
- PYTHONPATH=/volumes/base_dependencies/
volumes:
- dependencies:/volumes/base_dependencies
volumes:
dependencies:
Now the volume "dependencies" is shared successfully between the containers, but I want to also share it with the host. How can I do that?
The question is equivalent to how to specify a path of a named volume:
Solution:
volumes:
dependencies:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: '/abs/path/to/dependencies'
EDIT
The complete flow would be like,
Image: Dependency generator, at build time (docker build), generate dependency to /temp, then at run time (docker run / docker-compose up), cp -pr /temp /dependencies, after that it can exit 0.
My docker-compose defines two containers. I want one container shares a volume to the other container.
version: '3'
services:
web-server:
env_file: .env
container_name: web-server
image: web-server
build:
dockerfile: docker/Dockerfile
ports:
- 3000:3000
- 3500:3500
volumes:
- static-content: /workspace/static
command: sh /workspace/start.sh
backend-server:
volumes:
- static-content: /workspace/static
volumes:
static-content:
The above docker composer file declares two services, web-server and backend-server. And I declares the named volume static-content under services. I got below error when I run docker-composer -f docker-composer.yml up:
services.web-server.volumes contains an invalid type, it should be a string
services.backend-server.volumes contains an invalid type, it should be a string
so how can I share volumes throw docker-composer?
You have an extra space in your volume string that causes Yaml to change the parsing from an array of strings to an array of name/value maps. Remove that space in your volume entries (see below) to prevent this error:
version: '3'
services:
web-server:
env_file: .env
container_name: web-server
image: web-server
build:
dockerfile: docker/Dockerfile
ports:
- 3000:3000
- 3500:3500
volumes:
- static-content:/workspace/static
command: sh /workspace/start.sh
backend-server:
volumes:
- static-content:/workspace/static
volumes:
static-content:
For more details, see the compose file section on volumes short syntax.
You need to use the docker volumes syntax, without spaces
<local_path>:<service_path>:<optional_rw_attributes>
For example:
./:/your_path/
will map the present working directory to /your_path
And this example:
./:/your_path/:ro
will map the present working directory to /your_path with read only permissions
Read these docs for more info:
https://docs.docker.com/compose/compose-file/#volume-configuration-reference
I have the following docker-compose.yaml:
web:
build: web
volumes:
- .:/data
And web/Dockerfile is like this:
FROM ubuntu
RUN start_some_service.sh
But that data volume isn't being mounted. docker inspect says so:
"Volumes": null
Any idea what I'm doing wrong here?
Also tried:
volumes:
- ".:/app"
But the problem persists.
docker-compose -f docker-compose.yaml config shows the following:
services:
web:
build:
context: /Users/zoran/code/test/web
network_mode: bridge
volumes:
- /Users/zoran/code/test:/app:rw
version: '2.1'
It is necessary to specify both build and image options for the volumes to be mounted:
web:
build: web
image: my-web-image
volumes:
- .:/data
For development purposes I'm using docker compose in a VirtualBox running in OSX. To start the magic I run something like this (dkc=docker-compose)
$ dkc -f base.yml -f development.yml up -d --build
My docker compose files would be something like this:
base.yml
version: '2'
services:
padeltotal-app:
build:
context: ./padeltotal
dockerfile: Dockerfile.app
container_name: 'padeltotal-app'
links:
- padeltotal-mysql:db
ports:
- "9000:9000"
padeltotal-mysql:
build:
context: ./padeltotal
dockerfile: Dockerfile.db
container_name: 'padeltotal-mysql'
ports:
- "3306:3306"
nginx-lt:
extends:
file: common.yml
service: nginx
volumes_from:
- padeltotal-app
development:
version: '2'
services:
padeltotal-app:
volumes:
- ./padeltotal/code/src:/var/www/padeltotal/src
It's a PHP+MySql application
While I'm developing I'd like to have the volume with the PHP code I've mounted updated reflecting the changes from my ./padeltotal folder.
The default behaviour of the mounted volumen should be to reflect the HOST folder. However, in OSX is not working that way
I repeat, it's for development purposes, for production mode I don't even use docker compose
Is there a way to re-mount the volume?
What would be a different approach?