Given that I have a docker-compose.yml with a service explicitly stating the following
Should I not then have access to that device when I run the container? I find no such device when running ls -l on /dev
but If I run it with the following configuration of docker run --device /dev/ttyUSB0 I find it within the container successfully. I assumed the docker-compose devices key did this for us?
version: "3.9"
services:
influxdb:
container_name: influxdb
image: influxdb:latest
volumes:
- type: volume
source: dbdata
target: /var/lib/influxdb2
env_file:
- ./influx2.env
ports:
- 8086:8086
deploy:
restart_policy:
condition: on-failure
max_attempts: 5
privileged: true
backend:
image: golang
depends_on:
- influxdb
build:
context: ../
links:
- influxdb
devices:
- '/dev/ttyUSB0:/dev/ttyUSB0'
privileged: true
volumes:
- type: volume
source: dbdata
target: /var/lib/influxdb2
volumes:
dbdata:
Related
My goal: generate docker-compose.yaml from docker-compose.yaml and docker-compose.override.yaml and keep the variables as they are now = without interpolate
I've tried to run
docker compose -f docker-compose.yaml -f docker-compose.override.yaml convert --no-interpolate > new-docker-compose.yaml
Here is my docker-compose.yaml:
version: "3.5"
services:
redis-db:
image: redislabs/rejson:2.0.11
container_name: redis-db
restart: unless-stopped
volumes:
- redis-storage-vol:/data
- ${PWD}/config/redis/redis.conf:/usr/local/etc/redis/redis.conf:ro
ports:
- 6379:6379
runner:
image: "${REPO}/runner/${RUNNER_CPU_IMAGE}:${RUNNER_CPU_TAG}"
container_name: runner
restart: unless-stopped
volumes:
- data-storage-vol:/data
- ${PWD}/config/runner/runner-configuration.ini:/configuration.ini:ro
- "${PWD}/solutions/${ALGO}:/home/scripts/algorithmic_solutions_list.txt:ro"
depends_on:
- "redis-db"
gateway:
image: "${REPO}/gateway/gateway-server:${GATEWAY_TAG}"
container_name: gateway
restart: unless-stopped
volumes:
- data-storage-vol:/data
- ${PWD}/config/gateway/gateway-configuration.ini:/configuration.ini:ro
ports:
- 8000:8000
depends_on:
- "redis-db"
volumes:
data-storage-vol:
driver_opts:
type: "tmpfs"
device: "tmpfs"
o: "size=5g,uid=1000"
redis-storage-vol:
driver: local
docker-compose.override.yaml
version: "3.5"
services:
runner:
image: "${REPO}/runner/${RUNNER_GPU_IMAGE}:${RUNNER_GPU_TAG}"
deploy:
resources:
reservations:
devices:
- driver: nvidia
capabilities: [ GPU ]
What I've tried:
Run docker compose convert without flag --no-interpolate, it worked well but the variables was populated.
Run like the example - but got this error:
service "gateway" refers to undefined volume ${PWD}/config/gateway/gateway-configuration.ini: invalid compose project
I want to keep using docker compose commands and not edit files after its created.
Massive Docker noob here in dire need of help. There are two docker containers: simple-jar and elk. simple-jar produces log files in /logs directory within its container, and another application, elk, needs to access these log files to do some processing on them.
How can I share the /logs directory so that elk docker container can access it?
This is the Dockerfile for simple-jar:
FROM openjdk:latest
COPY target/pulsar_logging_consumer-1.0-SNAPSHOT-jar-with-dependencies.jar /usr/src/pulsar_logging_consumer-1.0-SNAPSHOT-jar-with-dependencies.jar
EXPOSE 6650
CMD java -jar /usr/src/pulsar_logging_consumer-1.0-SNAPSHOT-jar-with-dependencies.jar
docker-compose.yml:
version: '3.2'
services:
elk:
build:
context: elasticsearch/
args:
ELK_VERSION: $ELK_VERSION
volumes:
- type: bind
source: ./elasticsearch/config/elasticsearch.yml
target: /usr/share/elasticsearch/config/elasticsearch.yml
read_only: true
- type: volume
source: elasticsearch
target: /usr/share/elasticsearch/data
ports:
- "9200:9200"
- "9300:9300"
simple-jar:
build:
context: pulsar_logging_consumer/
volumes:
- type: bind
source: ./pulsar_logging_consumer/logs
target: /usr/share/logs
read_only: true
ports:
- "6500:6500"
networks:
- elk
depends_on:
- elasticsearch
networks:
elk:
driver: bridge
volumes:
elasticsearch:
You have a couple of options,
1. Create an external named volume, this needs to be created by you (the user) otherwise fails, using the following command
docker volume create --driver local \
--opt type=none \
--opt device=/var/opt/my_data_logs \
--opt o=bind logs_data
Select the volume type that fits, there are different types like nfs, ext3 and 3rd party plugins.
In your docker-compose.yml file
version '3'
volumes:
logs_data:
external: true
services:
app:
image: yourimage:latest
ports:
- 80:80
volumes:
- logs_data:/your/path
Share volumes: Start a container using volumes defined by another, (top-level volumes)
version '3'
volumes:
logs_data:
external: true
services:
app1:
image: appimage:latest
ports:
- 80:80
volumes:
- logs_data:/your/path:ro
app2:
image: yourimage:latest
ports:
- 8080:80
volumes:
- logs_data:/your/path:ro
You can do this by using --link See how to link container in docker?
An better way is to use volumes https://docs.docker.com/storage/volumes/
Using Docker toolbox on Windows 10 Home, Docker version 19.03, we have created a docker-compose.yml and added a secrets file as JSON, it runs fine on a Mac system, but it is unable to run the same in Windows 10 Home.
Error after running docker-compose up:
ERROR: for orthancserver Cannot create container for service orthanc: invalid mount config for type
"bind": invalid mount path: 'C:/Users/ABC/Desktop/Project/orthanc.json' mount path must be absolute
docker-compose.yml:
version: "3.7"
services:
orthanc:
image: jodogne/orthanc-plugins:1.6.1
command: /run/secrets/
container_name: orthancserver
restart: always
ports:
- "4242:4242"
- "8042:8042"
networks:
- mynetwork
volumes:
- /tmp/orthanc-db/:/var/lib/orthanc/db/
secrets:
- orthanc.json
dcserver:
build: ./dc_node_server
depends_on:
- orthanc
container_name: dcserver
restart: always
ports:
- "5001:5001"
networks:
- mynetwork
volumes:
- localdb:/database
volumes:
localdb:
external: true
networks:
mynetwork:
external: true
secrets:
orthanc.json:
file: orthanc.json
orthanc.json file kept next to docker-compose.yml
Found an alternative solution for windows 10 home, with docker toolbox. as commented by #Schwarz54, the file-sharing works well with docker volume for Dockerized Orthanc server.
Add shared folder:
Open Oracle VM manager
Go to setting of default VM
Click Shared Folders
Add C:\ drive to the list
Edit docker-compose.yml to transfer the config file to Orthanc via volume
version: "3.7"
services:
orthanc:
image: jodogne/orthanc-plugins:1.6.1
command: /run/secrets/
container_name: orthancserver
restart: always
ports:
- "4242:4242"
- "8042:8042"
networks:
- mynetwork
volumes:
- /tmp/orthanc-db/:/var/lib/orthanc/db/
- /c/Users/ABCUser/Desktop/Project/orthanc.json:/etc/orthanc/orthanc.json:ro
dcserver:
build: ./dc_node_server
depends_on:
- orthanc
container_name: dcserver
restart: always
ports:
- "5001:5001"
networks:
- mynetwork
volumes:
- localdb:/database
volumes:
localdb:
external: true
networks:
mynetwork:
external: true
I am trying to deploy my docker stack using compose file. When I deploy with compose file version 3+, the deploy works perfectly fine. But when I am trying to use the 2.4 version or lower I get this error:
unsupported Compose file version: 2.4
I need to use the 2.4 version, because Version 3 and higher does not support several parameters I need for my containers (such as cpuset and runtime).
My version of docker is 19.03.6 and docker-compose is 1.25.4.
Is there any way to deploy with an older version of compose file on Docker 19.03.6? Am I missing something or is the latest docker version does not support the older compose files anymore?
UPDATE
It turns out that docker 19.03.6 supports only Version 3+ in deploy. So I can't use anything but Version 3+, which does not provide the same flexibility as V2.4 in terms of CPU usage setup. The only solution in this situation (when you need parameters like cpuset and runtime) would be to run containers manually or move to something like Kubernetes.
Here are compose files examples:
Version 3.7 (working)
version: '3.7'
services:
mongo:
image: mongo
volumes:
- ~/ProcessingServerData/mongodb/db:/data/db
- ~/ProcessingServerData/mongodb/configdb:/data/configdb
networks:
- proc-net
mongo-express:
image: mongo-express
depends_on:
- mongo
ports:
- 8081:8081
networks:
- proc-net
visualizer:
image: dockersamples/visualizer:stable
ports:
- 8082:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- proc-net
deploy:
placement:
constraints: [node.role == manager]
networks:
proc-net:
driver: overlay
attachable: true
Version 2.4 (not working)
version: '2.4'
services:
mongo:
image: mongo
volumes:
- type: bind
source: ~/ProcessingServerData/mongodb/db
target: /data/db
- type: bind
source: ~/ProcessingServerData/mongodb/configdb
target: /data/configdb
networks:
- proc-net
deploy:
resources:
cpuset: 0,1
mongo-express:
image: mongo-express
depends_on:
- mongo
ports:
- 8081:8081
networks:
- proc-net
deploy:
resources:
cpuset: 0,1
visualizer:
image: dockersamples/visualizer:stable
ports:
- 8082:8080
volumes:
- type: bind
source: /var/run/docker.sock
target: /var/run/docker.sock
networks:
- proc-net
deploy:
resources:
cpuset: 0,1
placement:
constraints: [node.role == manager]
networks:
proc-net:
driver: overlay
deploy config option is not supported in 2.4 , you need to change the file to this one
version: '2.4'
services:
mongo:
image: mongo
volumes:
- type: bind
source: ~/ProcessingServerData/mongodb/db
target: /data/db
- type: bind
source: ~/ProcessingServerData/mongodb/configdb
target: /data/configdb
networks:
- proc-net
mongo-express:
image: mongo-express
depends_on:
- mongo
ports:
- 8081:8081
networks:
- proc-net
visualizer:
image: dockersamples/visualizer:stable
ports:
- 8082:8080
volumes:
- type: bind
source: /var/run/docker.sock
target: /var/run/docker.sock
networks:
- proc-net
networks:
proc-net:
driver: overlay
Apparently there is no support for an older compose file version for deploy.
https://forums.docker.com/t/cant-deploy-stack-with-compose-file-version-2-4-on-docker-19-03-6/90119
This is my docker-stack.yml file
version: "3"
services:
mysql:
image: mysql:latest
deploy:
replicas: 1
update_config:
parallelism: 1
restart_policy:
condition: on-failure
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: <Censored>
MYSQL_USER: <Censored>
MYSQL_PASSWORD: <Censored>
volumes:
- ./db/data:/var/lib/mysql
- ./db/logs:/var/log/mysql
- ./db/config:/etc/mysql/conf.d
php:
image: wiput1999/php
volumes:
- ./web:/web
nginx:
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./code:/code:ro
- ./site.conf:/etc/nginx/conf.d/default.conf
- /etc/letsencrypt:/etc/letsencrypt
- ./nginx/log:/var/log/nginx
When I run this following stack I got mysql and nginx with this error
"invalid mount config for type "bind": bind source path does not exist"
I have no idea what wrong with my code.
bind is a type of mount that is used to mount a directory (or a file) on the host into the container. All of your volumes are set up like that. So one of your source directories (or files) do not exists on the host. Check each of these:
./db/data
./db/logs
./db/config
./web
./code
./site.conf
/etc/letsencrypt
./nginx/log
You could execute ls -ld ./db/data ./db/logs ./db/config ./web ./code ./site.conf /etc/letsencrypt ./nginx/log >/dev/null and look at the error message to find out which one.
Please consider to use docker configs and docker secrets in place of volumes.
version: "3.3"
services:
nginx:
configs:
- source: nginx_vhost
target: /etc/nginx/conf.d/default.conf
secrets:
- ssl_private_key
...
configs:
nginx_vhost:
file: ./site.conf
secrets:
ssl_private_key:
file: /etc/letsencrypt/private.key
https://docs.docker.com/engine/swarm/configs/ and https://docs.docker.com/compose/compose-file/#configs