docker Advent Calendar 2021。 1日目記事の紹介です。
https://qiita.com/advent-calendar/2021/docker
ご投稿ありがとうございます。
@subretu DockerfileにおけるCMDとRUNの挙動
https://qiita.com/subretu/items/31a387510f84daaa4c1c
Github
資料はGithubにある。
https://github.com/subretu/docker-express-vuejs
$ git clone https://github.com/subretu/docker-express-vuejs
$ cd docker-express-vuejs
以下、今の所エラーで進んでいない。
Errror
Docker Compose
$ docker compose build
Docker Compose
Usage:
docker compose [command]
Available Commands:
convert Converts the compose file to a cloud format (default: cloudformation)
down
logs
ls
ps
up
Flags:
-h, --help help for compose
Global Flags:
--config DIRECTORY Location of the client config files DIRECTORY (default "/Users/ogawakiyoshi/.docker")
-c, --context string context
-D, --debug enable debug output in the logs
-H, --host string Daemon socket(s) to connect to
Use "docker compose [command] --help" for more information about a command.
ERROR: Service 'app' failed to build : COPY failed: stat /var/lib/docker/tmp/docker-
$ docker-compose build
Building app
Step 1/8 : FROM node:12.22.1-alpine
12.22.1-alpine: Pulling from library/node
ddad3d7c1e96: Pull complete
8a6a62f4b1f3: Pull complete
5c72c204eb22: Pull complete
33fce3bc6102: Pull complete
Digest: sha256:93b71facf11d471ac035acfaf020ecc05297f6a401781cafceae1d0561704ba4
Status: Downloaded newer image for node:12.22.1-alpine
---> ba59ff60c386
Step 2/8 : WORKDIR /app
---> Running in 06f080744e8c
Removing intermediate container 06f080744e8c
---> 617495260d38
Step 3/8 : COPY ./src/package.json ./src/yarn.lock ./src/server.js ./
---> f694ffef68d1
Step 4/8 : COPY ./src/vue_project/ ./vue_project
ERROR: Service 'app' failed to build : COPY failed: stat /var/lib/docker/tmp/docker-builder464320337/src/vue_project: no such file or directory
Githubを見ると、./src の下に、./vue_project はみ当たっていない。
エラーになるコピーコマンドをコメントにして実行。
dockerfileの最初のCOPYコマンドをコメントにしてみた。
$ docker-compose build
Building app
Step 1/7 : FROM node:12.22.1-alpine
---> ba59ff60c386
Step 2/7 : WORKDIR /app
---> Using cache
---> 617495260d38
Step 3/7 : COPY ./src/package.json ./src/yarn.lock ./src/server.js ./
---> Using cache
---> f694ffef68d1
Step 4/7 : RUN yarn install
---> Running in 9d326252dfc2
yarn install v1.22.5
[1/4] Resolving packages...
warning express-generator > mkdirp@0.5.1: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 3.58s.
Removing intermediate container 9d326252dfc2
---> 46e26d7d7560
Step 5/7 : RUN yarn global add @vue/cli
---> Running in a66bdf0f14d2
yarn global v1.22.5
[1/4] Resolving packages...
warning @vue/cli > @vue/cli-shared-utils > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning @vue/cli > @vue/cli-shared-utils > @hapi/joi@15.1.1: Switch to 'npm install joi'
warning @vue/cli > @vue/cli-shared-utils > request > har-validator@5.1.5: this library is no longer supported
warning @vue/cli > @vue/cli-shared-utils > request > uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
warning @vue/cli > @vue/cli-shared-utils > @hapi/joi > @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
warning @vue/cli > @vue/cli-shared-utils > @hapi/joi > @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
warning @vue/cli > @vue/cli-shared-utils > @hapi/joi > @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
warning @vue/cli > @vue/cli-shared-utils > @hapi/joi > @hapi/topo > @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
warning @vue/cli > @vue/cli-shared-utils > @hapi/joi > @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
warning @vue/cli > @vue/cli-ui > apollo-server-express > graphql-tools@4.0.8: This package has been deprecated and now it only exports makeExecutableSchema.\nAnd it will no longer receive updates.\nWe recommend you to migrate to scoped packages such as @graphql-tools/schema, @graphql-tools/utils and etc.\nCheck out https://www.graphql-tools.com to learn what package you should use instead
warning @vue/cli > @vue/cli-ui > apollo-server-express > graphql-tools > uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
warning @vue/cli > @vue/cli-ui > apollo-server-express > apollo-server-core > graphql-tools@4.0.8: This package has been deprecated and now it only exports makeExecutableSchema.\nAnd it will no longer receive updates.\nWe recommend you to migrate to scoped packages such as @graphql-tools/schema, @graphql-tools/utils and etc.\nCheck out https://www.graphql-tools.com to learn what package you should use instead
warning @vue/cli > @vue/cli-ui > apollo-server-express > apollo-server-core > apollo-cache-control@0.14.0: The functionality provided by the `apollo-cache-control` package is built in to `apollo-server-core` starting with Apollo Server 3. See https://www.apollographql.com/docs/apollo-server/migration/#cachecontrol for details.
warning @vue/cli > @vue/cli-ui > apollo-server-express > apollo-server-core > apollo-tracing@0.15.0: The `apollo-tracing` package is no longer part of Apollo Server 3. See https://www.apollographql.com/docs/apollo-server/migration/#tracing for details
warning @vue/cli > globby > fast-glob > micromatch > snapdragon > source-map-resolve > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
warning @vue/cli > globby > fast-glob > micromatch > snapdragon > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
warning @vue/cli > @vue/cli-ui > apollo-server-express > apollo-server-core > graphql-extensions@0.15.0: The `graphql-extensions` API has been removed from Apollo Server 3. Use the plugin API instead: https://www.apollographql.com/docs/apollo-server/integrations/plugins/
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "@vue/cli@4.5.15" with binaries:
- vue
Done in 58.92s.
Removing intermediate container a66bdf0f14d2
---> dce41701b017
Step 6/7 : WORKDIR /app/vue_project
---> Running in 4cd1c40bc6bc
Removing intermediate container 4cd1c40bc6bc
---> 1e67df929cb5
Step 7/7 : CMD ["yarn", "serve"]
---> Running in 6259d6218fa0
Removing intermediate container 6259d6218fa0
---> 1e0cef55acfb
Successfully built 1e0cef55acfb
Successfully tagged docker-express-vuejs_app:latest
Command "compose up" not available in current context (default)
$ docker compose up -d
Command "compose up" not available in current context (default)
Cannot find module '/app/vue_project/server.js'
dockerfileの最後の行を
RUN node server.js
に変更して実行。
$ docker-compose build
Building app
Step 1/7 : FROM node:12.22.1-alpine
---> ba59ff60c386
Step 2/7 : WORKDIR /app
---> Using cache
---> 617495260d38
Step 3/7 : COPY ./src/package.json ./src/yarn.lock ./src/server.js ./
---> Using cache
---> f694ffef68d1
Step 4/7 : RUN yarn install
---> Using cache
---> 46e26d7d7560
Step 5/7 : RUN yarn global add @vue/cli
---> Using cache
---> dce41701b017
Step 6/7 : WORKDIR /app/vue_project
---> Using cache
---> 1e67df929cb5
Step 7/7 : RUN node server.js
---> Running in 7c1cf3379576
internal/modules/cjs/loader.js:818
throw err;
^
Error: Cannot find module '/app/vue_project/server.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
at Function.Module._load (internal/modules/cjs/loader.js:667:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
ERROR: Service 'app' failed to build : The command '/bin/sh -c node server.js' returned a non-zero code: 1
参考資料
docker-compose
https://qiita.com/haruki_uejima/items/7cf161f1cc39d8a0c67d
Docker Compose - docker-compose.yml リファレンス
https://qiita.com/zembutsu/items/9e9d80e05e36e882caaa
Docker Compose を試す
https://qiita.com/hideyuki/items/bf372c521379fd43b42a
最後までおよみいただきありがとうございました。
いいね 💚、フォローをお願いします。
Thank you very much for reading to the last sentence.
Please press the like icon 💚 and follow me for your happy life.