Hello nystateofhealth@hasham1983,
You’re encountering an issue with copying files from your Dockerfile into the container when using Docker Compose. Let’s troubleshoot this together.
The problem you’re facing might be related to how volumes are mounted in Docker Compose. Let’s break down the issue and provide a solution.
In your docker-compose.yaml, you’ve defined a volume for your service:
volumes:
- ./carrier:/var/local/Config/
This volume mounts the local directory ./carrier (from your host machine) into the container at /var/local/Config/.
When you use volumes, the content inside the container’s target directory (/var/local/Config/) is replaced by the content from the host directory (./carrier).
In your Dockerfile, you’re copying the shell script from the context directory into the container:
COPY ./shell.sh /tmp/hasham/
The COPY command should work as expected, but the issue arises when the volume is mounted.
When you run your container using Docker Compose, the volume mount (./carrier:/var/local/Config/) takes precedence over the content inside the container.
As a result, the shell script copied during the build process is overwritten by the empty directory from the host.
To fix this, you can modify your Dockerfile to copy the shell script directly into the target directory (/var/local/Config/) instead of relying on the volume mount.
Update your Dockerfile as follows:
FROM alpine:latest
LABEL maintainer="hasham1983@yahoo.com"
RUN mkdir -p /tmp/hasham
COPY ./shell.sh /var/local/Config/
RUN chmod 775 /var/local/Config/shell.sh
RUN echo '*/1 * * * * /var/local/Config/shell.sh' > /etc/crontabs/root
CMD crond && sleep infinite
By copying the script directly into the container’s target directory, it won’t be affected by the volume mount.
After updating your Dockerfile, rebuild your image:
docker-compose build
Then run your container using Docker Compose:
docker-compose up -d
Check if the shell script is correctly placed inside the container:
docker exec -it myapp ls -al /var/local/Config/
This modification should ensure that your shell script is copied correctly into the container even when using Docker Compose.
Best Regards,
nystateofhealth