Copy folder in docker entrypoint sh script produces wrong folder name
I have a small docker based project and I want to copy my local .ssh folder inside then modify folder permissions.
- In the docker-compose.yml I mount my .ssh folder to the container’s tmp/.ssh folder.
- Then on startup I copy the contents of tmp/.ssh to root/.ssh and change the folder permissions.
(This step is needed because when would install my PHP packages via composer, it would complain that the folder permissions are too open)
Unfortunately there is something wrong with my .sh script because the folder’s name what it creates in /root looks like this: ‘.ssh’$’r’
docker-compose.yml:
version: '3.7'
services:
sandbox:
build:
context: ./
dockerfile: ./Dockerfile
volumes:
- .:/var/www/html
- ~/.ssh:/tmp/.ssh
restart: always
ports:
- "8060:80"
environment:
- APACHE_RUN_DIR=/var/run/apache2
- APACHE_RUN_USER=#1000
- APACHE_RUN_GROUP=#1000
- APACHE_LOG_DIR=/var/log/apache2
- APACHE_PID_FILE=/tmp/apache2.pid
- APACHE_LOCK_DIR=/var/lock/apache2
- JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
Dockerfile:
FROM php:7.4.1-apache-buster
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
RUN a2enmod rewrite
COPY vhost-configs/vhost.local.conf /etc/apache2/sites-available/
COPY vhost-configs/vhost.local.conf /etc/apache2/sites-enabled/
RUN rm /etc/apache2/sites-enabled/000-default.conf
EXPOSE 80
COPY docker-entrypoint.sh /bin/docker-entrypoint.sh
RUN chmod 777 /bin/docker-entrypoint.sh && chmod +x /bin/docker-entrypoint.sh
CMD /usr/sbin/apache2 -DFOREGROUND
ENTRYPOINT ["sh", "/bin/docker-entrypoint.sh"]
docker-entrypoint.sh:
#!/bin/sh -e
cp -R /tmp/.ssh /root/.ssh
chmod 700 /root/.ssh
chmod 400 /root/.ssh/id_rsa
exec "[email protected]"
Source: Docker Questions