Docker终端命令
docker run -dp 3000:3000 -w /app -v "$(pwd):/app" node:12-alpine sh -c "yarn install && yarn run dev"
我对上述代码行有问题。我在Cmder、GitBash和Windows 10 PowerShell终端中运行这行代码。
控制台1 - Cmder - 错误:
docker: Error response from daemon: create $(pwd): "$(pwd)" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
See 'docker run --help'.
控制台 2 - GitBash - `错误`:
docker: Error response from daemon: the working directory 'C:/Program Files/Git/app' is invalid, it needs to be an absolute path.
See 'docker run --help'.
可能的原因:
https://github.com/docker/cli/issues/2204
控制台3 - Windows PowerShell -“成功”:
df1ad0a4f71016f7832b6d9d02f963f33cc2cc8d5740e1013561287d875fb5de
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
df1ad0a4f710 node:12-alpine "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 0.0.0.0:3000->3000/tcp exciting_liskov
37d12fa854d7 mysql:5.7 "docker-entrypoint.s…" 3 hours ago Up 3 hours 3306/tcp, 33060/tcp admiring_faraday
23803e6325db docker/getting-started "/docker-entrypoint.…" 13 hours ago Up 13 hours 0.0.0.0:80->80/tcp boring_banach
$ docker logs
$ docker
df1ad0a4f71016f7832b6d9d02f963f33cc2cc8d5740e1013561287d875fb5de
yarn install v1.22.5
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.52s.
yarn run v1.22.5
$ nodemon src/index.js
[nodemon] 1.19.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node src/index.js`
Using sqlite database at /etc/todos/todo.db
Listening on port 3000
PS C:\WEB APPS\app\app>
我想知道你是否能在GitBash或Cmder上工作,还是这是我的环境问题?猜测大多数人会在Mack OS或Linux发行版上运行它。也许vagrant + docker是正确的选择?你在Windows上的设置是什么?
回到控制台2 - GitBash - 尝试解决可能的路径问题:
所以根据上面的问题,我修改了该行,添加了额外的“/”(如何停止MinGW和MSYS破坏命令行中给出的路径名)。
docker run -dp 3000:3000 -w //app -v "$(pwd)/app" node:12-alpine sh -c "yarn install && yarn run dev"
cfde24fc30e8a8d3e83cade4a00ee318e37ced1d90aa831f0d56b9dc7148be22
现在Docker容器已经创建,但尚未运行...请查看以下问题 $ docker日志
cfde24fc30e8a8d3e83cade4a00ee318e37ced1d90aa831f0d56b9dc7148be22
yarn install v1.22.5
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 0.04s.
yarn run v1.22.5
error Couldn't find a package.json file in "/app"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
现在我们遇到了一个错误
Couldn't find a package.json file in "/app"
,有人能在 gitbash 中解决这个问题吗?
docker run
命令试图在当前目录的内容上运行 Node...安装本地的 Node 是否比尝试将 Docker 插入其中更容易?可以从 https://nodejs.org/en/download/ 下载并安装 Node。 - David Maze