Docker 撰写卷无效字符

Docker 撰写卷无效字符

无法使用 docker-compose up 启动容器

Docker version 1.9.1, build a34a1d5

Dockerfile

FROM ubuntu

# File Author / Maintainer
MAINTAINER Parzee [email protected]

# 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

docker-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

答案1

yaml 对 docker compose 的要求非常严格。请确保路径是绝对路径(对于主机端)并且不包含尾随空格。

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

应该

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

没有引号!我加引号是为了突出问题。

如果你确实需要相对路径,请考虑使用起重机而不是docker-compose。

答案2

要在部分中使用相对路径volumes,您必须添加./,例如

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

或者从命令行,例如:

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

相关内容