Ubuntu

Docker 撰寫卷無效字元

  • March 11, 2019

無法使用 docker-compose up 啟動容器

Docker version 1.9.1, build a34a1d5

Dockerfile

FROM ubuntu

# File Author / Maintainer
MAINTAINER Parzee info@parzee.com

# Install Components.

# Update the repository
ENV LANG en_US.UTF-8
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update
RUN locale-gen en_US en_US.UTF-8
# Install necessary tools
RUN apt-get install -y nano vim wget dialog net-tools
RUN apt-get install lighttpd -y
RUN apt-get install php5-common php5-cgi php5 -y
RUN lighty-enable-mod fastcgi-php
RUN update-rc.d -f lighttpd disable
RUN mkdir -p /usr/local/src/imbue/application/imbue/utils/security/des

ADD lighttpd.conf /etc/lighttpd/

VOLUME ["/var/log/lighttpd"]

RUN ls -al /etc/lighttpd/lighttpd.conf

RUN /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf

EXPOSE 8083

碼頭工人-compose.yml

lighttpd:
 image: parzee/lighttpd
 ports: 
   - "8083:8083"
 volumes:
   - volumes/log:/var/log/lighttpd 

當我執行時:

docker run -h lighttpd -p 8083:8083 -d -v `pwd`/volumes/log:/var/log/lighttpd -t parzee/lighttpd

我的容器啟動正常,但使用docker-compose up我收到以下錯誤:

Creating lighttpd_lighttpd_1
ERROR: volumes/log includes invalid characters for a local volume name, only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed

這是文件結構:

.
├── docker-compose.yml
├── Dockerfile
├── lighttpd.conf
└── volumes
   ├── etc
   │   └── lighttpd
   │       └── lighttpd.conf
   └── log

4 directories, 4 files

yaml 對 docker compose 非常挑剔。確保路徑是絕對的(對於主機端)並且不包含尾隨空格。

"- volumes/log:/var/log/lighttpd "

應該

"- /host/path/volumes/log:/var/log/lighttpd"

沒有引號!我把它們放進去是為了突出這個問題。

如果您確實需要相對路徑,請考慮使用起重機而不是 docker-compose。

要在部分中使用相對路徑volumes,您必須添加./,例如

 volumes:
   - ./volumes/log:/var/log/lighttpd

或者從命令行,例如:

docker run -v $PWD/volumes/log:/var/log/lighttpd ...

引用自:https://serverfault.com/questions/757175