Windows 卷上的 docker-compose 不起作用 [英] docker-compose on Windows volume not working
问题描述
过去一周我一直在使用 Docker,我认为容器的想法非常有用,但是尽管在过去 3 天里我阅读了所有我能读的内容,但我还是无法让卷映射工作
I've been playing with Docker for the past week and think the container idea is very useful, but despite reading everything I can for the past 3 days I can't get the volume mapping to work
get docker-compose to use my existing volume.
Docker Version: 18.03.1-ce
docker-compose version 1.21.1, build 7641a569
I created a volume using the following via a Dockerfile
# Reference SQL image
FROM microsoft/mssql-server-windows-developer
# Create directory within SQL container for database files mapped to the volume
VOLUME sqldata:c:/MSSQL
and here it shows:
C:\ProgramData\Docker\volumes>docker volume ls
local sqldata
Now I've tried probably 60+ different "solutions" based on StackOverflow and Docker forums, but none of them work. (Note despite the names below with Azure I am simply trying to get this to run locally, Azure is next hurdle)
Docker-compose.yaml:
version: '3.4'
services:
ws:
image: wsManager
container_name: azure-wcf
ports:
- "80"
depends_on:
- db
db:
image: dbimage:latest
container_name: azure-db
volumes:
- \sqldata:/mssql
# - type: volume
# source: sqldata
# target: /mssql
ports:
- "1433"
I've added a volumes section but it does not help,
volumes:
sqldata:
external:
name: sqldata
changed the - \sqldata:/mssql
to every possible slash .. . ~ whatever. Moved the file to yaml file
到 C:\ProgramData\Docker\volumes - 基本上是我的搜索结果中显示的任何建议.dbImage 是一个 SQL Server 映像,我需要从中保存数据,但我想知道它有什么神奇之处,因为我尝试过的任何方法都不起作用.非常感谢任何帮助.
to C:\ProgramData\Docker\volumes - basically any suggestion that showed in my search results. The dbImage is a SQL Server image that I need to persist the data from but am wondering what the magic is as nothing I've tried works. Any help is GREATLY appreciated.
我在 Windows 10 Pro build 1803 上运行.
I'm running on Windows 10 Pro build 1803.
为什么要这么难?比你知道如何使这个真正起作用的人.
Why does this have to be so hard? Than you to whomever knows how to make this actually work.
推荐答案
解决方案是在 Windows 上使用 volumes: 选项引用真实路径,如下所示:
The solution is to reference the true path on Windows using the volumes: option as below:
sqldb:
image: sqlimage
container_name: azure-db
volumes:
- "C:\\ProgramData\\Docker\\volumes\\sqldata:c:\\mssql"
为了保持数据,我使用了以下内容:
To persist the data I used the following:
environment:
- "sa_password=ddsql2017@@"
- "ACCEPT_EULA=Y"
- 'attach_dbs= {"dbName":"MyDb","dbFiles":"C:\\MSSQL\\MyDb.mdf","C:\\MSSQL\\MyDb.ldf"]}]'
希望这对其他人有所帮助,因为我发现在 SO 和其他地方搜索的许多示例对我都不起作用,并且在 Docker 论坛中有很多帖子说安装卷不适用于 Windows.
Hope this helps someone else as many of the examples I found searching both on SO and elsewhere did not work for me, and in the Docker forums there are a lot of posts saying mounting volumes not work for Windows.
这篇关于Windows 卷上的 docker-compose 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!