I have a Dockerfile where I am copying in a shell script called myscript.sh
that I want to run each time a container made from the image starts. The script copies in fine but will not execute when the container starts. Once the container starts, I can interactively connect and manually run the script with no issues but it won't run at start.
Contents of myscript.sh
:
#!/bin/bash
mkdir -p /root/newfolder
Dockerfile:
FROM ubuntu:20.04
COPY ./src* /src
COPY ./myscript.sh /usr/local/bin
CMD ["/usr/local/bin/myscript.sh"]
I have also tried:
CMD ["/bin/bash", "/usr/local/bin/myscript.sh"]
When I run docker run -it -d --name {container_name} {image_name} bash
it creates a container from the image and gives me shell prompt. I check to see if the script created the folder but it does not. If I then interactively run the script, the folder is created with no issues.
I have looked at other solutions and none seem to work. What am I missing?