docker 有捲權限,但 docker-compose 沒有
我已經在 Amazon Linux 伺服器上安裝了 Docker,並為其授予了
sudo usermod -aG docker $USER
./var/lib/docker/volumes
當我從命令行啟動我的 Jenkins docker 容器(在 EBS 安裝卷上具有主目錄,安裝在)時;docker run -d \ --restart=always \ --name=jenkins-core \ --hostname=jenkins-core \ -p 8080:8080 \ -p 50000:50000 \ --env JENKINS_OPTS="--prefix=/core" \ -v jenkins-core:/var/jenkins_home \ jenkins/jenkins:lts
一切正常。但是,當我嘗試從它開始
docker-compose up -d
或sudo docker-compose up -d
得到時;touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
並且 docker 容器進入引導循環,試圖重新啟動。我無法弄清楚為什麼權限錯誤
docker-compose
但在docker
.我試過
sudo chown $(whoami):$(whoami) /usr/local/bin/docker-compose
了,但沒有用。我docker-compose
從這里安裝;https://docs.docker.com/compose/install/這是
docker-compose.yml
還有一個.env
變數文件(未附加)version: "3.6" services: jenkins-core: image: jenkins/jenkins:lts container_name: jenkins-core restart: always ports: - ${JENKINS_CORE_HOST_PORT_8080}:${JENKINS_PORT_8080} - ${JENKINS_CORE_HOST_PORT_50000}:${JENKINS_PORT_50000} environment: - JENKINS_OPTS=--prefix=${JENKINS_CORE_PREFIX} - JAVA_OPTS=-Duser.timezone=${TZ} volumes: - ${JENKINS_CORE_HOME_DIR}:/var/jenkins_home jenkins-integrations: image: jenkins/jenkins:lts container_name: jenkins-integrations restart: always ports: - ${JENKINS_INTEGRATIONS_HOST_PORT_8080}:${JENKINS_PORT_8080} - ${JENKINS_INTEGRATIONS_HOST_PORT_50000}:${JENKINS_PORT_50000} environment: - JENKINS_OPTS=--prefix=${JENKINS_INTEGRATIONS_PREFIX} - JAVA_OPTS=-Duser.timezone=${TZ} volumes: - ${JENKINS_INTEGRATIONS_HOME_DIR}:/var/jenkins_home portainer: image: portainer/portainer container_name: portainer restart: always environment: - TZ=${TZ} ports: - ${PORTAINER_PORT_9000}:9000 volumes: - /etc/localtime:/etc/localtime:ro - /var/run/docker.sock:/var/run/docker.sock - ${DOCKERCONFDIR}/portainer:/data command: -H unix:///var/run/docker.sock watchtower: image: v2tec/watchtower container_name: watchtower restart: always environment: - TZ=${TZ} volumes: - /var/run/docker.sock:/var/run/docker.sock command: --schedule 0 0 4 * * * --cleanup
請在此處查看:https ://github.com/jenkinsci/docker/blob/master/README.md在用法下。它說
NOTE: Avoid using a bind mount from a folder on the host machine into /var/jenkins_home, as this might result in file permission issues (the user used inside the container might not have rights to the folder on the host machine)...
所以你的
docker run
作品的原因是因為docker 卷-v jenkins-core:/var/jenkins_home
在哪裡。jenkins-core
但是,在撰寫中,您使用綁定掛載到主機上的某個文件夾。