In Docker Compose file, how to enable GPU in service build instructions? - docker

I am trying to build service from docker file when start docker compose. The docker-compose.yml looks like:
version: '3'
services:
app:
build:
context: .
shm_size: 4gb
# ...
The build process need to enable GPU. I know how to enable GPU in deploy according to this blog. But it seems docker compose file build do not support GPU.

I think, I have read two different method.
The simple, try that:
https://docs.docker.com/compose/gpu-support/
https://www.tremplin-numerique.org/en/how-to-run-compose-docker-containers-with-gpu-access
services:
test:
image: nvidia/cuda:10.2-base
command: nvidia-smi
runtime: nvidia
The complex,
It run a docker via a run.
Then via docker compose, it connect to its docker.
In this method, it describes all steps.
https://dinhanhthi.com/docker-gpu/
docker run \
--gpus all\
--name docker_thi_test\
--rm\
-v abc:abc\
-p 8888:8888
Yaml
version: '2'
services:
jupyter:
container_name: 'docker_thi_test'
build: .
volumes:
- ./notebooks:/tf/notebooks
ports:
- 8888:8888
environment:
- NVIDIA_VISIBLE_DEVICES=0
- PASSWORD=12345

Related

docker-compose "depends_on", but with "docker run"

How can I implement the below docker-compose code, but using the docker run command? I am specifically interested in the depends_on part.
version: '2'
services:
db:
image: postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
depends_on: doesn't map to a docker run option. When you have your two docker run commands you need to make sure you put them in the right order.
docker build -t web_image .
docker network create some_network
docker run --name db --net some_network postgres
# because this depends_on: [db] it must be second
docker run --name web --net some_network ... web_image ...
depends-on mean :
Compose implementations MUST guarantee dependency services have been started before starting a dependent service. Compose implementations MAY wait for dependency services to be “ready” before starting a dependent service.
Hence the depends on is not only an order of running
and you can use docker-compose instead of docker run and every option in docker run can be in the docker-compose file

is there is any way we can use bind mount in dockerfile or it neccessary to use compose-file.yml

how can we use below sample code in Docker-file
sample 1
docker container run -p 80:4000 -v $(pwd):/site/jekyll-serve
sample 2
docker container run -p 8080:80 --name web2 -v $(pwd):/usr/share/nginx/html nginx
i have recently started learning docker and swarm orchestration just need to know about this issue. is there any update in future release or any fixes to this....???
as of 9/9/21 you need to use docker compose
https://docs.docker.com/compose/networking/
services:
web:
build: .
ports:
- "80:4000"
https://docs.docker.com/storage/volumes/
services:
frontend:
volumes:
- $(pwd):/site/jekyll-serve
volumes:
myapp:
Named volumes: Docker-compose named mounted volume
my-named-volume:
driver_opts:
type: none
device: /home/full/path #NOTE needs full path (~ doesn't work)
o: bind

Issue with docker not acknowledging docker-compose.override.yml

I'm particularly new to Docker. I was trying to containerize a project for development and production versions. I came up with a very basic docker-compose configuration and then tried the override feature which doesn't seem to work.
I added overrides for volumes to web and celery services which do not actually mount to the container, can confirm the same by looking at the inspect log of both the containers.
Contents of compose files:-
docker-compose.yml
version: '3'
services:
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
depends_on:
- redis
redis:
image: redis:5.0.9-alpine
celery:
build: .
command: celery worker -A facedetect.celeryapp -l INFO --concurrency=1 --without-gossip --without-heartbeat
depends_on:
- redis
environment:
- C_FORCE_ROOT=true
docker-compose.override.yml
version: '3'
services:
web:
volumes:
- .:/code
ports:
- "8000:8000"
celery:
volumes:
- .:/code
I use Docker with Pycharm on Windows 10.
Command executed to deploy the compose configuration:-
C:\Program Files\Docker Toolbox\docker-compose.exe" -f <full-path>/docker-compose.yml up -d
Command executed to inspect one of the containers:-
docker container inspect <container_id>
Any help would be appreciated! :)
Just figured out that I had provided the docker-compose.yml file explicitly to the Run Configuration created in Pycharm as it was mandatory to provide at least one of these.
The command used by Pycharm explicitly mentions the .yml files using -f option when running the configuration. Adding the docker-compose.override.yml file to the Run Configuration changed the command to
C:\Program Files\Docker Toolbox\docker-compose.exe" -f <full_path>\docker-compose.yml -f <full_path>/docker-compose.override.yml up -d
This solved the issue. Thanks to Exadra37 directing to look out for the command that was being executed.

How do I convert this docker command to docker-compose?

I run this command manually:
$ docker run -it --rm \
--network app-tier \
bitnami/cassandra:latest cqlsh --username cassandra --password cassandra cassandra-server
But I don't know how to convert it to a docker compose file, specially the container's custom properties such as --username and --password.
What should I write in a docker-compose.yaml file to obtain the same result?
Thanks
Here is a sample of how others have done it. http://abiasforaction.net/apache-cassandra-cluster-docker/
Running the command below
command:
Setting arg's below
environment:
Remember just because you can doesn't mean you should.. Compose is not always the best way to launch something. Often it can be the lazy way.
If your running this as a service id suggest building the dockerfile to start and then creating systemd/init scripts to rm/relaunch it.
an example cassandra docker-compose.yml might be
version: '2'
services:
cassandra:
image: 'bitnami/cassandra:latest'
ports:
- '7000:7000'
- '7001:7001'
- '9042:9042'
- '9160:9160'
volumes:
- 'cassandra_data:/bitnami'
volumes:
cassandra_data:
driver: local
although this will not provide you with your commandline arguments but start it with the default CMD or ENTRYPOINT.
As you are actually running another command then the default you might not want to do this with docker-compose. Or you can create a new Docker image with this command as the default and provide the username and password as ENV's
e.g. something like this (untested)
FROM bitnami/cassandra:latest
ENV USER=cassandra
ENV PASSWORD=password
CMD ["cqlsh", "--username", "$USER", "--password", "$PASSWORD", "cassandra-server"]
and you can build it
docker build -t mycassandra .
and run it with something like:
docker run -it -e "USER=foo" -e "PASSWORD=bar" mycassandra
or in docker-compose
services:
cassandra:
image: 'mycassandra'
ports:
- '7000:7000'
- '7001:7001'
- '9042:9042'
- '9160:9160'
environment:
USER:user
PASSWORD:pass
volumes:
- 'cassandra_data:/bitnami'
volumes:
cassandra_data:
driver: local
You might looking for something like the following. Not sure if it is going to help you....
version: '3'
services:
my_app:
image: bitnami/cassandra:latest
command: /bin/sh -c cqlsh --username cassandra --password cassandra cassandra-server
ports:
- "8080:8080"
networks:
- app-tier
networks:
app-tier:
external: true

How to Specify $docker build --network="host" mode in docker-compose at the time of build

While building docker image like docker build -t name:tag --network="host" so it will Set the networking mode for the RUN instructions during build (default "default")
So I am trying to build Docker image with DOKCER-COMPOSE:
version: '3'
services:
ezmove-2.0:
network_mode: "host"
build:
context: .
ports:
- "5000:5000"
So as per above compose file I am trying to build image but how to Specify --network="host" mode in docker-compose at the time of build
#dkanejs is right, and here is how you use it (the version number is important):
version: '3.4'
services:
my_image:
build:
context: .
network: host
Looks as though the option was added in the latest version but is nowhere to be found in the docker-compose online documentation.

Resources