当前位置:优学网  >  在线题库

docker run 中的路径使用 pwd 和写死有什么区别?

发表时间:2022-05-12 13:57:29 阅读:13.1k

我想在 docker 中跑 onedev

根据 官方教程 中的指示,我使用了下面的命令:

docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd)/onedev:/opt/onedev -p 6610:6610 -p 6611:6611 1dev/server

可以跑通 ✅:

─➤  docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd)/onedev:/opt/onedev -p 6610:6610 -p 6611:6611 1dev/server
INFO  - Launching application from '/app'...
INFO  - Starting server...
INFO  - Populating /opt/onedev...
INFO  - Successfully populated /opt/onedev
05:44:42 INFO  i.onedev.commons.bootstrap.Bootstrap - Launching application from '/opt/onedev'...
05:44:42 INFO  io.onedev.commons.loader.AppLoader - Starting server...

我想写成 docker-compose.yaml 文件:

version: "3"

services:
  onedev-server:
    container_name: onedev-server
    image: 1dev/server
    ports:
      - 6610:6610
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker
      - $(pwd)/onedev:/opt/onedev

但是 docker-compose 好像不支持 $(pwd) 这种语法,报错如下 ❌ :

─➤  docker-compose up                                         
ERROR: Invalid interpolation format for "volumes" option in service "onedev-server": "$(pwd):/opt/onedev"

所以我打算把 $(pwd) 写死,改为如下:

version: "3"

services:
  onedev-server:
    container_name: onedev-server
    image: 1dev/server
    ports:
      - 6610:6610
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker
      - /home/bot/Desktop/code/ideaboom/test_onedev:/opt/onedev

当前路径如下:

─➤  pwd
/home/bot/Desktop/code/ideaboom/test_onedev

但是报错了 ❌ :

─➤  docker-compose up
Starting onedev-server ... done
Attaching to onedev-server
onedev-server    | INFO  - Launching application from '/app'...
onedev-server    | INFO  - Cleaning temp directory...
onedev-server    | INFO  - Starting server...
onedev-server    | ERROR - Invalid OneDev installation directory: /opt/onedev, make sure you are specifying the top level installation directory (it contains sub directories such as "bin", "boot", "conf", etc)
onedev-server exited with code 1

我不理解!

🎖️ 优质答案
  • 改成这样就好了:

    version: "3"
    
    services:
      onedev-server:
        container_name: onedev-server
        image: 1dev/server
        ports:
          - 6610:6610
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
          - /usr/bin/docker:/usr/bin/docker
          - /home/bot/Desktop/code/ideaboom/test_onedev/onedev:/opt/onedev
  • 相关问题