简体   繁体   English

在 docker 入口点复制文件夹 sh 脚本产生错误的文件夹名称

[英]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.我有一个基于 docker 的小项目,我想复制我的 local.ssh 文件夹,然后修改文件夹权限。

  1. In the docker-compose.yml I mount my.ssh folder to the container's tmp/.ssh folder.在 docker-compose.yml 中,我将 my.ssh 文件夹挂载到容器的 tmp/.ssh 文件夹中。
  2. Then on startup I copy the contents of tmp/.ssh to root/.ssh and change the folder permissions.然后在启动时,我将 tmp/.ssh 的内容复制到 root/.ssh 并更改文件夹权限。 (This step is needed because when would install my PHP packages via composer, it would complain that the folder permissions are too open) (需要这一步,因为什么时候通过composer安装我的PHP包,它会抱怨文件夹权限太开放)

Unfortunately there is something wrong with my.sh script because the folder's name what it creates in /root looks like this: '.ssh'$'\r'不幸的是,my.sh 脚本有问题,因为它在 /root 中创建的文件夹名称如下所示: '.ssh'$'\r'

docker-compose.yml: 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: 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: docker-入口点.sh:

#!/bin/sh -e
cp -R /tmp/.ssh /root/.ssh
chmod 700 /root/.ssh
chmod 400 /root/.ssh/id_rsa
exec "$@"

The docker-entrypoint.sh file was created on windows and contained dos line endings. docker-entrypoint.sh 文件创建于 windows 并包含 dos 行结尾。

I installed dos2unix and converted the file inside the container:我安装了 dos2unix 并在容器内转换了文件:

RUN apt-get install -y dos2unix


RUN dos2unix /bin/docker-entrypoint.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM