Volume defined in docker-compose not mounting - docker

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

Related

Unique directory name of mount volume per Docker container

Current docker-compose.yml:
version: "3.5"
services:
dev_service:
image: my-image
build:
context: .
target: my-image
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- "6080:80"
- "6022:22"
volumes:
- './workspace/logs:/var/log/peimp'
This is fine for a single container instance, but not many.
Logs will be overwritten.
Is there any way to automatically create unique directories that will be shared on the host system?
e.g.
./workspace/logs_1,
./workspace/logs_2
You could use an ENV variable like this:
version: "3.5"
services:
dev_service:
image: my-image
build:
context: .
target: my-image
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- "6080:80"
- "6022:22"
volumes:
- './workspace/logs${LOG_NUM}:/var/log/peimp'
And then run the docker compose like this:
export LOG_NUM=1 && docker-compose up

docke named volume doesn't appear

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.

Use Docker Compose to create multiple containers

I am completely new to Docker. I have a sonarqube image. I wrote a sample Docker Compose file and ran the image. Everything is working fine. Now I want to create 5-6 containers using Docker Compose.
How can I do this?
This is my sample YAML file:
version: '2'
services:
web:
build: .
ports:
- "9000:9000"
depends_on:
- my_image
my_image:
image: mySonarApp
I also would be interested in knowing if it is possible to create them only with my docker config file.
Just add more service definitions
version: '2'
services:
weba:
build: .
ports:
- "9000:9000"
weba:
build: .
ports:
- "9001:9000"
webc:
build: .
ports:
- "9002:9000"
You can use the scale command to create more instances of the service:
docker-compose scale web=6

Re-mount volume in a running container

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?

Docker compose with two files

I have two docker-compose.yml files in separate folders.
I'd like to run the two of them in the same command, in order for the services from both to be able to talk to each other.
However, when I go to the lowest common path ancestor and try to run docker-compose with both files, here is what happens:
$ docker-compose -f ./api-folder/docker-compose.yml -f ./front-folder/docker-compose.yml up -d
ERROR: build path /projects/front-folder/api either does not exist, is not accessible, or is not a valid URL.
$ docker-compose -f ./front-folder/docker-compose.yml -f ./api-folder/docker-compose.yml up -d
ERROR: build path /projects/api-folder/app either does not exist, is not accessible, or is not a valid URL.
Here are the two docker-compose.yml files:
/projects/front-folder/docker-compose.yml
version: '2'
services:
app:
restart: always
build: ./app
environment:
NODE_ENV: 'dev'
ports:
- "4400:4400"
volumes:
- ./app:/usr/src/app
nginx:
restart: always
build: ./nginx
volumes:
- ./logs:/usr/local/var/log/nginx
links:
- app
ports:
- "80:80"
/projects/api-folder/docker-compose.yml
version: '2'
services:
api:
restart: always
build: ./api
expose:
- "4600"
volumes:
- ./api:/usr/src/app
- ./logs:/logs
nginx:
restart: always
build: ./nginx
volumes:
- ./logs:/usr/local/var/log/nginx
links:
- api
ports:
- "81:80"
networks:
- hackerz
And the directory structure:
- /projects
- /front-folder
- /app
Dockerfile
- /nginx
Dockerfile
docker-compose.yml
- /api-folder
- /api
Dockerfile
- /nginx
Dockerfile
docker-compose.yml
I'm guessing the problem is with the build paths, but what I don't understand is:
Why Docker insists on searching build: ./api in /front-folder or the other way around?
How to circumvent this problem and be able to run both files together?
DOCKERFILE
Alternate Dockerfile.
Compose uses an alternate file to build with. A build path must also be specified.
service3:
build:
context: .
dockerfile: Dockerfile-alternate
docker compose build giving custom file
This isn't how compose works (by design). See my comment here: https://github.com/docker/compose/issues/3530#issuecomment-222490501.

Resources