类型“ bind”的无效安装配置。 Docker适用于MacO,但不适用于Win10和ubuntu

时间:2019-12-11 13:27:10

标签: linux windows docker docker-compose dockerfile

我是一名学生,我的同事为我们的项目设置了docker环境,它正在MacO上运行。她暂时待命了。

我正在尝试在Windows 10上运行此环境以在家中工作,但是我遇到Invalid mount config for type "bind"的问题。

我为Windows安装了docker-desktop并启用了hyper-v。

这是我的配置文件:

./ docker-compose.yml:

version: '3.7'
services:
  sql:
    image: mysql
    networks:
      - matcha_network
    ports:
      - 3306:3306
    container_name: 'matcha_db'
    volumes:
      - db_data:/var/lib/mysql
    restart: unless-stopped
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=matcha
    command: '--default-authentication-plugin=mysql_native_password'

  phpMyAdmin:
    image: phpmyadmin/phpmyadmin
    networks:
      - matcha_network
    ports:
      - 3307:80
    depends_on:
      - sql
    environment:
      - PMA_HOST=matcha_db
      - PMA_PORT=3306
    container_name: phpMyAdmin

  sinatra:
    build:
      context: .
      dockerfile: Sinatra.Dockerfile
    image: matcha-sinatra:v0.1
    ports:
      - '4567:4567'
    restart: always
    networks:
      - matcha_network
    environment:
      - APP_ENV=development
      - IP=${REACT_APP_SERVER_IP}
      - MT_USER=${MAILTRAP_USERNAME}
      - MT_PASS=${MAILTRAP_PASSWORD}
      - HMAC=${HMAC_SECRET}
    depends_on:
      - sql
    volumes:
      - type: bind
        source: ./src/server
        target: /app
        read_only: true

networks:
  matcha_network:

volumes:
  db_data:

./ Script.Dockerfile:

FROM ubuntu

WORKDIR /

RUN apt-get update
RUN apt-get install -y ruby mysql-client libmysqlclient-dev bundler vim libssl-dev
RUN gem install mysql2
RUN gem install bcrypt faker

./ Sinatra.Dockerfile:

FROM ruby

WORKDIR /app

EXPOSE 4567

COPY src/server/Gemfile .

RUN gem install bundler rerun bcrypt mysql2 jwt thin
RUN bundle install

CMD rerun --background --force-polling -- ruby /app/index.rb -o 0.0.0.0

./ src / server / Gemfile:

source 'https://rubygems.org'

gem 'sinatra'
gem 'sinatra-cross_origin'

要设置环境,我在Windows上使用以下命令:

docker-machine create --driver hyperv --hyperv-virtual-switch "DockerMatcha" --hyperv-boot2docker-url https://github.com/boot2docker/boot2docker/releases/download/v18.06.0-ce/boot2docker.iso matcha-machine

 - logs:
Running pre-create checks...
(matcha-machine) Downloading C:\Users\arago\.docker\machine\cache\boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v18.06.0-ce/boot2docker.iso...
(matcha-machine) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
(matcha-machine) Creating VM...
(matcha-machine) Creating VHD
(matcha-machine) Starting VM...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: C:\Program Files\Docker\Docker\Resources\bin\docker-machine.exe env matcha-machine

然后我使用docker-machine ip matcha-machine获取机器的IP,然后将其设置在.env中。

最后我愿意:

docker-compose up

 - logs
Creating network "matcha_matcha_network" with the default driver
Creating volume "matcha_db_data" with default driver
Pulling sql (mysql:)...
latest: Pulling from library/mysql
d599a449871e: Pull complete
f287049d3170: Pull complete
08947732a1b0: Pull complete
96f3056887f2: Pull complete
871f7f65f017: Pull complete
1dd50c4b99cb: Pull complete
5bcbdf508448: Pull complete
a59dcbc3daa2: Pull complete
13e6809ab808: Pull complete
2148d51b084d: Pull complete
93982f7293d7: Pull complete
e736330a6d9c: Pull complete
Digest: sha256:c93ba1bafd65888947f5cd8bd45deb7b996885ec2a16c574c530c389335e9169
Status: Downloaded newer image for mysql:latest
Pulling phpMyAdmin (phpmyadmin/phpmyadmin:)...
latest: Pulling from phpmyadmin/phpmyadmin
000eee12ec04: Pull complete
8ae4f9fcfeea: Pull complete
60f22fbbd07a: Pull complete
ccc7a63ad75f: Pull complete
a2427b8dd6e7: Pull complete
91cac3b30184: Pull complete
d6e40015fc10: Pull complete
240e21c03bb4: Pull complete
504858e1e4aa: Pull complete
9a0523b2d73f: Pull complete
163ef1a69c2e: Pull complete
1a564803a07b: Pull complete
4ae2a0882c31: Pull complete
0ba6971ca6fc: Pull complete
55652e94064a: Pull complete
9e59ee976f51: Pull complete
0dc245440bd0: Pull complete
f0139774ec90: Pull complete
97f5943225b5: Pull complete
Digest: sha256:996393cc538b9a08dae7ecf7620898534e029f3ecd7c2f88922e597571d7ccd2
Status: Downloaded newer image for phpmyadmin/phpmyadmin:latest
Building sinatra
Step 1/7 : FROM ruby
latest: Pulling from library/ruby
16ea0e8c8879: Pull complete
50024b0106d5: Pull complete
ff95660c6937: Pull complete
9c7d0e5c0bc2: Pull complete
29c4fb388fdf: Pull complete
069ad1aadbe0: Pull complete
e7188792d9dd: Pull complete
bae7e74440d1: Pull complete
Digest: sha256:2285f291f222e1b53d22449cc52bad2112f519bcce60248ea1c4d5e8f14c7c04
Status: Downloaded newer image for ruby:latest
 ---> 2ff4e698f315
Step 2/7 : WORKDIR /app
 ---> Running in 41bc1bfc323d
Removing intermediate container 41bc1bfc323d
 ---> d79c0930751b
Step 3/7 : EXPOSE 4567
 ---> Running in 8d199bf2cf9e
Removing intermediate container 8d199bf2cf9e
 ---> fe5a2b546265
Step 4/7 : COPY src/server/Gemfile .
 ---> 408311562c66
Step 5/7 : RUN gem install bundler rerun bcrypt mysql2 jwt thin
 ---> Running in 66970e56921f
Successfully installed bundler-2.0.2
Successfully installed rb-fsevent-0.10.3
Building native extensions. This could take a while...
Successfully installed ffi-1.11.3
Successfully installed rb-inotify-0.10.0
Successfully installed listen-3.2.1
Successfully installed rerun-0.13.0
Building native extensions. This could take a while...
Successfully installed bcrypt-3.1.13
Building native extensions. This could take a while...
Successfully installed mysql2-0.5.3
Successfully installed jwt-2.2.1
Successfully installed daemons-1.3.1
Building native extensions. This could take a while...
Successfully installed eventmachine-1.2.7
Successfully installed rack-2.0.7
Building native extensions. This could take a while...
Successfully installed thin-1.7.2
13 gems installed
Removing intermediate container 66970e56921f
 ---> e87eafe7b51f
Step 6/7 : RUN bundle install
 ---> Running in 61e4809ef5b0
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Using bundler 2.0.2
Fetching mustermann 1.0.3
Installing mustermann 1.0.3
Using rack 2.0.7
Fetching rack-protection 2.0.7
Installing rack-protection 2.0.7
Fetching tilt 2.0.10
Installing tilt 2.0.10
Fetching sinatra 2.0.7
Installing sinatra 2.0.7
Fetching sinatra-cross_origin 0.4.0
Installing sinatra-cross_origin 0.4.0
Bundled gems are installed into `/usr/local/bundle`
Removing intermediate container 61e4809ef5b0
 ---> ff899ee8a495
Step 7/7 : CMD rerun --background --force-polling -- ruby /app/index.rb -o 0.0.0.0
 ---> Running in 41f1dc9e2168
Removing intermediate container 41f1dc9e2168
 ---> 650df7c0ef5d

Successfully built 650df7c0ef5d
Successfully tagged matcha-sinatra:v0.1
WARNING: Image for service sinatra was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating matcha_db ... done
Creating phpMyAdmin ...
Creating matcha_sinatra_1 ... error
Creating phpMyAdmin       ... done
ERROR: for matcha_sinatra_1  Cannot create container for service sinatra: invalid mount config for type "bind": bind mount source path does not exist: /c/Users/arago/Documents/42/matcha/src/server

ERROR: for sinatra  Cannot create container for service sinatra: invalid mount config for type "bind": bind mount source path does not exist: /c/Users/arago/Documents/42/matcha/src/server
ERROR: Encountered errors while bringing up the project.

要在Macos上运行此环境,我们有一个脚本可以使所有操作自动化:

脚本:


machine='matcha-machine'

if ! docker-machine status $machine > /dev/null 2>&1
then
  docker-machine create \
  --virtualbox-boot2docker-url \
  https://github.com/boot2docker/boot2docker/releases/download/v18.06.0-ce/boot2docker.iso \
  $machine
fi

docker-machine start $machine
eval $(docker-machine env $machine)
server_ip=$(docker-machine ip matcha-machine)
sed -i '' "s/REACT_APP_SERVER_IP=.*/REACT_APP_SERVER_IP=${server_ip}/" .env
docker-compose up

使用此脚本在macOS上一切正常,但在ubuntu上出现与win10相同的错误:

Creating matcha_sinatra_1 ... error
ERROR: for matcha_sinatra_1  Cannot create container for service sinatra: invalid mount config for type "bind": bind mount source path does not exist: /c/Users/arago/Documents/42/matcha/src/server

ERROR: for sinatra  Cannot create container for service sinatra: invalid mount config for type "bind": bind mount source path does not exist: /c/Users/arago/Documents/42/matcha/src/server
ERROR: Encountered errors while bringing up the project.

我对此感到困惑,不知道为什么会出现此错误。你能帮我吗?

谢谢。

0 个答案:

没有答案