我是docker的初学者,我在YouTube https://www.youtube.com/watch?v=gAkwW2tuIqE&ab_channel=Fireship上关注了本教程
我已经在我的应用程序文件夹中创建了一个dockerfile。
FROM node:13
WORKDIR /
COPY package*.json ./
RUN npm install
#ngelakuin run di shell (ini buat di shell)
COPY . .
#copy semua file di dalam directory ini
ENV PORT=3000
#menyesuaikan dimana port aplikasi berjalan, port = 3000
EXPOSE 3000
#expose port public
CMD ["npm", "start"]
#ngelakuin run (cmd)
该教程说,在执行docker build
之前,它应该运行8条命令(直到cmd命令)。但就我而言,只有5个(直到COPY . .
)
这是码头工人建造码头时要做的事情。
[+] Building 12.7s (9/9) FINISHED
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 382B 0.0s
=> [internal] load metadata for docker.io/library/node:13 2.7s
=> => transferring context: 57.03kB 0.2s
=> [2/5] COPY package*.json ./ 0.0s
=> [3/5] RUN npm install 9.3s
=> [4/5] COPY . . 0.1s
=> exporting to image 0.2s
=> => exporting layers 0.2s
=> => writing image sha256:93fde5bd0e36d551a0545e1ae6d69b7691d36361b2f75c6eafc2c48cd8ed54d1 0.0s
=> => naming to docker.io/hollyyph/docker-demo-holly:1.0 0.0s
我检查了是否可以运行该映像,但无法运行。变成这样
\docker-demo-holly > docker run sha256:93fde5bd0e36d551a0545e1ae6d69b7691d36361b2f75c6eafc2c48cd8ed54d1
> app-service-hello-world@0.0.1 start /
> node index.js
internal/modules/cjs/loader.js:965
throw err;
^
Error: Cannot find module 'express'
Require stack:
- /index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:962:15)
at Function.Module._load (internal/modules/cjs/loader.js:838:27)
at Module.require (internal/modules/cjs/loader.js:1022:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/index.js:1:17)
at Module._compile (internal/modules/cjs/loader.js:1118:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1138:10)
at Module.load (internal/modules/cjs/loader.js:982:32)
at Function.Module._load (internal/modules/cjs/loader.js:875:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/index.js' ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app-service-hello-world@0.0.1 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app-service-hello-world@0.0.1 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-11-01T19_10_00_543Z-debug.log