Docker compose throwing find: ‘’: No such file or directory - docker

I am trying to execute docker-compose on top of official Cassandra docker image.
Basically, I am trying to set a few of properties present inside Cassandra image at /etc/cassandra/cassandra.yaml .
My docker-compose looks like
version: '3.0'
services:
cassandra:
image: cassandra:3.11.6
ports:
- "9042:9042"
environment:
- CASSANDRA_ENABLE_USER_DEFINED_FUNCTIONS=true
# restart: always
volumes:
- ./cassandra-dc-1:/usr/local/bin/
container_name: cassandra-dc-1
entrypoint: /usr/local/bin/docker-entrypoint.sh
# command: /usr/local/bin/docker-entrypoint.sh
When I run docker-compose up --build I get below error, from the directory where I have the docker-compose.yaml present
cassandra-dc-1 | find: ‘’: No such file or directory
cassandra-dc-1 exited with code 1
I tried giving
Absolute path in the volume
./cassandra-dc-1:/usr/local/bin/ -- using this with file 'docker-entrypoint.sh' which I want to copy within docker
I am unable to figure out what is wrong.

Basically, I am trying to set a few of properties present inside
Cassandra image at /etc/cassandra/cassandra.yaml .
If you just to set properties in yaml file you do not need to override the entrypoint as it will hide a lot of executable not only entrypoint by doing below
volumes:
- ./cassandra-dc-1:/usr/local/bin/
Do not mound the whole directory /usr/local/bin/.
If you just want to override entrypoint then do the following
volumes:
- ./cassandra-dc-1/docker-entrypoint.sh:/usr/local/bin/docker-entrypoint.sh
Custom config file
FROM cassandra:3.11.6
copy my_customconfig.yml /etc/cassandra/cassandra.yaml
That's all you need to run with custom config, copy the config during build time.
or with docker-compose
volumes:
- ./cassandra.yaml:/etc/cassandra/cassandra.yaml
Configuring Cassandra

Related

How can I add a file to my volume without writing a new file to the host?

I'm trying to run a Next.js project inside docker-compose. To take advantage of hot-reloading, I'm mounting in the entire project to the Docker image as a volume.
So far, so good!
This is where things are starting to get tricky: For this particular project, it turns out Apple Silicon users need a .babelrc file included in their dockerized app, but NOT in the files on their computer.
All other users do not need a .babelrc file at all.
To sum up, this is what I'd like to be able to do:
hot reload project (hence ./:/usr/src/app/)
have an environment variable write content to /usr/src/app/.babelrc.
not have a .babelrc in the host's project root.
My attempt at solving was including the .babelrc under ci-cd/.babelrc in the host file system.
Then I tried mounting the file as a volume like - ./ci-cd/.babelrc:/usr/src/app/.babelrc. But then a .babelrc file gets written back to the root of the project in the host filesystem.
I also tried include COPY ./ci-cd/.babelrc /usr/src/app/.babelrc within the Dockerfile, but it seems to be overwritten with docker-composes's volume property.
Here's my Dockerfile:
FROM node:14
WORKDIR /usr/src/app/
COPY package.json .
RUN npm install
And the docker-compose.yml:
version: "3.8"
services:
# Database image
psql:
image: postgres:13
restart: unless-stopped
ports:
- 5432:5432
# image for next.js project
webapp:
build: .
command: >
bash -c "npm run dev"
ports:
- 3002:3002
expose:
- 3002
depends_on:
- testing-psql
volumes:
- ./:/usr/src/app/

How to create the directory in a Dockerfile

I struggle to create a directory in my Dockerfile below. Entering the container after building the image I can't find the directory "models". "ds" directory in path "/usr/src/app/ds/models" is an application directory which was copied. Could you please tell me what is wrong here.
FROM python:3.8
ENV PYTHONUNBUFFERED=1
ENV DISPLAY :0
WORKDIR /usr/src/app
COPY . .
RUN mkdir -p /usr/src/app/ds/models
My docker-compose.yaml file contains volume:
version: '3.8'
services:
app:
build: .
command:
- /bin/bash
- -c
- python manage.py runserver 0.0.0.0:8000
restart: always
volumes:
- .:/usr/src/app
ports:
- '8000:8000'
When your docker-compose.yml file says
volumes:
- .:/usr/src/app
that host directory completely replaces the /usr/src/app directory from your image. This means pretty much nothing in your Dockerfile has an effect; if you try to deploy this setup to another system, you've never run the code in the image.
I'd recommend deleting this block, and also the command: override (make it be the default CMD in the Dockerfile instead).
I need to download models to this directory
Mount only the specific directory you need into your container; don't overwrite the entire application tree. Potentially consider keeping that data directory in a different part of the filesystem.
version: '3.8'
services:
app:
build: .
# no command:
restart: always
volumes:
# only the models subdirectory, not the entire application
- ./ds/models:/usr/src/app/ds/models
ports:
- '8000:8000'

How to copy files inside container with docker-compose

I have a simple image that runs a jar file. That jar file inside the image needs a special configuration file in order to run.
In the location with the docker-compose.yml I have a folder named "carrier" and under this folder I have that file.
The docker-compose.yml:
version: "3.3"
services:
web:
image: "myimage:1.80.0.0"
ports:
- "61003:61003"
volumes:
- ./carrier:/var/local/Config/
When I hit docker-compose up it complains that the file is not there, so it doesn't copy it.
If I do another option like I did in the .sh command, something like this:
volumes:
- ./carrier:/var/local/Config/:shared
It complains about another error:
C:\Tasks\2246>docker-compose up
Removing 2246_web_1
Recreating 1fbf5d2bcea4_2246_web_1 ... error
ERROR: for 1fbf5d2bcea4_2246_web_1 Cannot start service web: path /host_mnt/c/Tasks/2246/carrier is mounted on / but it is not a shared mount
Can someone please help me?
Copy the files using Dockerfile, use below;
FROM myimage:1.80.0.0
RUN mkdir -p /var/local/Config/
COPY carrier /var/local/Config/
EXPOSE 61003
docker-compose.yml
version: "3.3"
services:
web:
build:
dockerfile: Dockerfile
context: '.'
ports:
- "61003:61003"
In the end, run below command to build new image and start container
docker-compose up -d --build
You can use Dockerfile if it does not copy.
Dockerfile;
FROM image
COPY files /var/local/Config/
EXPOSE 61003
Docker-compose;
version: "3.3"
services:
web:
build: . (path contains Dockerfile)
ports:
- "61003:61003"
volumes:
- ./carrier:/var/local/Config/
Remove the last /
volumes:
- ./carrier:/var/local/Config
I'm not sure but you can try to set full access permissions for all user to /carrier:
chmod -R 777 /carrier
Thanks all for all your answers.
Seems like finally docker warned me with some comparisons over the windows files vs Linux files when building the image. (Not with docker compose but with Dockerfile).
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
Tried it on linux and works.

creating a redis docker container with an exising rdb and load module at initiation?

I am trying to start a docker container using a redis db that I have a persistent copy saved to a local machine.
I currently have a docker container loading redis with a volume using this docker-compose.yml but it misses my redis.conf (which contains the loadmodule command) is located in the volume with the rdb file
version: '3'
services:
redis:
image: redis
container_name: "redis"
ports:
- "6379:6379"
volumes:
- E:\redis_backup_conf:/data
This begins to load the RDB but crashes out because the data uses this time series module.
I can load a seperate docker container with a fresh redis db that has the time seriese module loaded using the following dockerfile. My issue is I can't figure out how to do both at the same time!
Is there someway of calling a dockerfile from a docker-compose.yml or declaring the volume in the dockerfile?
That, or should I be creating my own image that I can call in the docker-compose.yml?
Any help woule be appreciated, I'm honeslty just going round in circles I think.
dockerfile
# BUILD redisfab/redistimeseries:${VERSION}-${ARCH}-${OSNICK}
ARG REDIS_VER=6.0.1
# stretch|bionic|buster
ARG OSNICK=buster
# ARCH=x64|arm64v8|arm32v7
ARG ARCH=x64
#----------------------------------------------------------------------------------------------
FROM redisfab/redis:${REDIS_VER}-${ARCH}-${OSNICK} AS builder
ARG REDIS_VER
ADD ./ /build
WORKDIR /build
RUN ./deps/readies/bin/getpy2
RUN ./system-setup.py
RUN make fetch
RUN make build
#----------------------------------------------------------------------------------------------
FROM redisfab/redis:${REDIS_VER}-${ARCH}-${OSNICK}
ARG REDIS_VER
ENV LIBDIR /usr/lib/redis/modules
WORKDIR /data
RUN mkdir -p "$LIBDIR"
COPY --from=builder /build/bin/redistimeseries.so "$LIBDIR"
EXPOSE 6379
CMD ["redis-server", "--loadmodule", "/usr/lib/redis/modules/redistimeseries.so"]
EDIT:
ok.. slight improvement i can call a redis-timeseries image in the docker-compose.yml
services:
redis:
image: redislabs/redistimeseries
container_name: "redis"
ports:
- "6379:6379"
volumes:
- E:\redis_backup_conf:/data
This is a start however I still need to increase the maximum number of db's, I have been using the redis.conf to do this in the past.
You can just have docker-compose build your dockerfile directly. Assume your docker-compose file is in folder called myproject . Also assume your dockerfile is in a folder called myredis and that myredis is in the myproject folder. Then you can replace this line in your docker-compose file:
Image: redis
With:
Build: ./myredis
That will build and use your custom image

Running a custom script using entrypoint in docker-compose

I modified the docker-compose.yml file as given on https://hub.docker.com/_/solr/ by adding a volumes configuration and a change in entrypoint. The modified file is as given:
version: '3'
services:
solr:
image: solr
ports:
- "8983:8983"
volumes:
- ./solr/init.sh:/init.sh
- ./solr/data:/opt/solr/server/solr/mycores
entrypoint:
- init.sh
- docker-entrypoint.sh
- solr-precreate
- mycore
I need to run this 'init.sh' before entrypoint starts, to prepare my files inside container.
But I get following errors:
ERROR: for solr_solr_1 Cannot start service solr: oci runtime error:
container_linux.go:247: starting container process caused "exec:
\"init.sh\": executable file not found in $PATH"
Earlier I found about official image hooks in neo4j from here. Is there a similar thing I can use here also?
Update 1: From comments below, I realized that dockerfile set WORKDIR /opt/solr due to which executable file not found in $PATH. So I tested by providing the absolute path to entrypoint by using /init.sh. But this also gives error, but a different one:
standard_init_linux.go:178: exec user process caused "exec format
error"
It looks like you need to map your volume to /docker-entrypoint-initdb.d/
version: '3'
services:
solr:
image: solr
ports:
- "8983:8983"
volumes:
- ./solr/init.sh:/docker-entrypoint-initdb.d/init.sh
- ./solr/data:/opt/solr/server/solr/mycores
entrypoint:
- docker-entrypoint.sh
- init
From
https://hub.docker.com/_/solr/
Extending the image The docker-solr image has an extension mechanism. At run time, before starting Solr, the container will
execute scripts in the /docker-entrypoint-initdb.d/ directory. You can
add your own scripts there either by using mounted volumes or by using
a custom Dockerfile. These scripts can for example copy a core
directory with pre-loaded data for continuous integration testing, or
modify the Solr configuration.
The docker-entrypoint.sh seems to be responsible for running the sh scripts based on the arguments passed to it. So init is the first argument which in turn tries to run init.sh
docker-compose logs solr | head
Update 1:
I had struggled to get this to work and finally figured out why my docker-compose was not working while the docker run -v pointing to the /docker-entrypoint-initdb.d/init.sh was working.
It turns out that removing the entrypoint tree was the solution. Here's my final docker-compose:
version: '3'
services:
solr:
image: solr:6.6-alpine
ports:
- "8983:8983"
volumes:
- ./solr/data/:/opt/solr/server/solr/
- ./solr/config/init.sh:/docker-entrypoint-initdb.d/init.sh
my ./solr/config/init.sh
#!/bin/bash
echo "running"
touch /opt/solr/server/solr/test.txt;
echo "test" > /opt/solr/server/solr/test.txt;
An alternative solution that worked for me was modifying entrypoint by placing /bin/sh.It looked a bit like this afterwards
version: '3'
services:
web:
build: .
volumes:
- .:/code
entrypoint :
- /bin/sh
- ./test.sh
ports:
- "5000:5000
where test.sh is the required bash script to be run inside the container.

Resources