Unable to add volume to image via docker-compose

心不动则不痛 提交于 2020-02-04 05:27:04

问题


I'm trying to add a volume to the mattermost/mattermost-preview docker image. The Dockerfile for this image (not controlled by me) is:

# Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
# See License.txt for license information.
FROM mysql:5.7

# Install ca-certificates to support TLS of Mattermost v3.5
RUN apt-get update && apt-get install -y ca-certificates

#
# Configure SQL
#

ENV MYSQL_ROOT_PASSWORD=mostest
ENV MYSQL_USER=mmuser
ENV MYSQL_PASSWORD=mostest
ENV MYSQL_DATABASE=mattermost_test

#
# Configure Mattermost
#
WORKDIR /mm

# Copy over files
ADD https://releases.mattermost.com/4.4.4/mattermost-team-4.4.4-linux-amd64.tar.gz .
RUN tar -zxvf ./mattermost-team-4.4.4-linux-amd64.tar.gz
ADD config_docker.json ./mattermost/config/config_docker.json
ADD docker-entry.sh .

RUN chmod +x ./docker-entry.sh
ENTRYPOINT ./docker-entry.sh

# Create default storage directory
RUN mkdir ./mattermost-data
VOLUME ./mattermost-data

# Ports
EXPOSE 8065

I want to add a volume to this image, and a custom entrypoint so that I can add some test data to the mysql database before my container starts up. I'm trying to use docker-compose to do this:

version: '3'
services:
  mattermost:
    ports:
     - "8065:8065"
    image: mattermost/mattermost-preview
    volumes:
      - ./end_to_end/mattermost/mock-mount:/mm/mock-mount
    entrypoint: /mm/mock-mount/docker-entry.sh

But I'm unfortunately not able to get this to start, when I try running docker-compose up, I get the error

ERROR: for mattermost  Cannot create container for service mattermost: invalid bind mount spec "39742853c03b3b2747f11c942a4a76e4cd138ad41d54f70f71d7aa9ccc36dcca:mattermost-data:rw": invalid volume specification: '39742853c03b3b2747f11c942a4a76e4cd138ad41d54f70f71d7aa9ccc36dcca:mattermost-data:rw': invalid mount config for type "volume": invalid mount path: 'mattermost-data' mount path must be absolute
ERROR: Encountered errors while bringing up the project.

The weird thing is - if I take out the volumes and entrypoint sections from my docker-compose.yml file, then the container starts up no problem, even though it seems to me that the error is with the original image. Is there a way to do what I want here?


回答1:


You cannot use a relative path when declaring a volume in a Dockerfile to be used with docker-compose:

VOLUME ./mattermost-data

As mentioned here, the question would be relative to what? Is it relative to some workdir of the container? Is it relative to the local filesystem while you're building the layer?

Usual practice is to create the volume with absolute paths, such as just /mattermost-data (so this mount point will be at the root level of the container).

In the compose file, a relative path is OK for the source path, but it is interpreted relative to the compose file itself ... so you have to be careful not to think that it is relative to some container path. Relative paths are still disallowed for the destination paths.

More details:

As reported here, relative paths for a VOLUME in a Dockerfile won't cause the Dockerfile to break necessarily, it's just that they are always treated relative to / and don't care about any intermediate WORKDIR or the temporary layers involved with creating the image, etc.

Basically, creating a relative VOLUME is going to create it at the top level if you manually perform docker build. For docker-compose though, it will not work at all, and throws the error that you are seeing.

You might want to file a bug report with the authors of that Dockerfile, since the usage of VOLUME ./mattermost-data hamstrings anyone downstream who wants to use that image drectly with docker-compose.




回答2:


i think in your image docker-remote.registry.kroger.com/mattermost/mattermost-preview not exist folder /mm/mock-mount.

Try change entrypoint to

entrypoint: /bin/bash -c "/mm/mock-mount/docker-entry.sh"



来源:https://stackoverflow.com/questions/47687893/unable-to-add-volume-to-image-via-docker-compose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!