- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我认为这是一个由两部分组成的错误,但这里的背景故事是我正在尝试学习 Docker。我想学习它以便在 Google Cloud Platform 上进行一些测试,并且我已经使用 Docker 文件创建了镜像,但是文件在我的机器上或容器内持久存在更改时遇到了问题。
Dockerfile(以备不时之需)
FROM ubuntu:latest
# Use Ubuntu as the base
RUN apt-get -y update && apt-get -y upgrade && apt-get -y install curl git
# update & updgrade all the apps. Also install cURL and Git (needed for node, apparently?)
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
# download the node 8.x setup (don't know the words on that one) file
RUN apt-get install -y nodejs
# Install NodeJS
RUN mkdir /var/www/ && mkdir /var/www/app/
# create the directory /var/www/ and then, inside of that directory, create the var/www/app/
WORKDIR /var/www/app/
# our work directory is the app directory
VOLUME /var/www/app
ADD . .
# add everything in the current directory on our file system to the work directory in our container
RUN npm install
# node apps need to have their dependencies installed
CMD ["npm", "start"]
#The command used when the docker container is run.
volume
docker-compose.yml
中的选项文件。所以,我试图自己创造一个。请注意,我已经评论了 dockerfile 关于我对它们的理解。如果我错了,或者注意完全正确,请纠正我,因为我想以正确的方式学习这一点。
version: "3"
#what docker-compose version are we using? 3.
services:
#describes the services to be build when this is composed up
web:
# we will have a web service -- in the future I will obviously need to have some form of database
build: ./
#where do we build this image from? the Dockerfile in this directory
image: dockertest_node
#what image will be named "dockertest_node" on my machine
container_name: node_test
#this container (once build), however, will be titled "node_test" to make it easier to work with and run docker exec commands
volumes:
- ./:/var/www/app
#volumes, as I understand them, are a map from acutal file system -> containerized file system
ports:
- "8080:8080"
# we expose port 8080 from my local machine to port 8080 on the container's machine.
const express = require('express');
const app = express();
app.get('/', (req,res)=>{
res.send('hello world, from express!');
});
app.listen(8080, (err)=>{
if(err) {
console.error(err);
return 1;
}
console.log('server started');
});
{
"name": "docker-test",
"version": "0.0.0",
"description": "Testing",
"dependencies": {
"express": "^4.0.0",
"bootstrap":"4.0.0-beta",
"jquery": "^3.0.0",
"popper.js":"^1.11.0"
},
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "",
"license": "ISC"
}
Docker version 17.09.1-ce, build 19e2cf6
docker-compose up
我收到以下错误
Starting node_test ...
Starting node_test ... done
Attaching to node_test
node_test |
node_test | > docker-test@0.0.0 start /var/www/app
node_test | > node index.js
node_test |
node_test | module.js:538
node_test | throw err;
node_test | ^
node_test |
node_test | Error: Cannot find module 'express'
node_test | at Function.Module._resolveFilename (module.js:536:15)
node_test | at Function.Module._load (module.js:466:25)
node_test | at Module.require (module.js:579:17)
node_test | at require (internal/module.js:11:18)
node_test | at Object.<anonymous> (/var/www/app/index.js:1:79)
node_test | at Module._compile (module.js:635:30)
node_test | at Object.Module._extensions..js (module.js:646:10)
node_test | at Module.load (module.js:554:32)
node_test | at tryModuleLoad (module.js:497:12)
node_test | at Function.Module._load (module.js:489:3)
node_test | npm ERR! code ELIFECYCLE
node_test | npm ERR! errno 1
node_test | npm ERR! docker-test@0.0.0 start: `node index.js`
node_test | npm ERR! Exit status 1
node_test | npm ERR!
node_test | npm ERR! Failed at the docker-test@0.0.0 start script.
node_test | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
node_test | npm WARN Local package.json exists, but node_modules missing, did you mean to install?
node_test |
node_test | npm ERR! A complete log of this run can be found in:
node_test | npm ERR! /root/.npm/_logs/2017-12-25T22_47_55_509Z-debug.log
node_test exited with code 1
.yml
中添加卷相关信息之前没有显示文件和 Dockerfile 本身。但是,我可以使用命令
docker exec -p 8080:8080 -it dockertest_node bash
登录到容器。 , 我可以手动运行
npm start
没有问题。
touch something.txt
该文件仅在容器内创建;反之亦然,我对 index.js 或 package.json 文件的任何更改都没有进入容器。
最佳答案
您收到此错误是因为主机和容器之间的第二个卷映射确实覆盖了现有数据。有关启动 docker 容器的更多信息,请访问 this wiki .由于您在 Dockerfile 上运行 npm install,因此您必须确保 mount /node_modules
作为 docker-compose 中的数据卷。
所以要克服这个问题,你需要:
VOLUME /var/www/app
ADD . /var/www/app
RUN npm install
…
volumes:
- ./: /var/www/app
- /var/www/app/node_modules
关于Docker 卷不持久更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47973831/
我正在使用以下dockerfile: FROM ubuntu:14.04 MAINTAINER xxx xxx # SSH RUN apt-get update && apt-get install
我运行了docker-compose build celery,(经过数小时的尝试,我的连接不良)成功了。 app Dockerfile的前80%是相同的,但不会重复使用缓存。从我可以浏览的内容来看,
我可以使用以下命令成功创建 Docker 注册表 v2 服务:docker service create 然后我使用 docker Push 将一些图像推送到该服务。 当我通过 curl localh
我正在尝试使用 gitlab 构建 CI,我从 docker 的 docker 镜像开始,我的前端存储库没有任何问题,但现在使用相同的 gitlab-ci 配置文件,我有此守护程序错误。 这是构建的输
用例: 我们在 Jenkins 中有几个“发布作业”build 和 push 应用程序的 Docker 镜像到 docker registry,更新各种文件中的项目版本,最后将发布标签推送到相应的 G
当我尝试构建我的 docker 文件时,docker 返回以下错误: [+] Building 0.0s (1/2)
docker-in-docker 的作者在此博客中建议不要将此图像用于 CI 目的: jpetazzo/Using Docker-in-Docker for your CI or testing en
我创建了一个 Dockerfile 来在 Docker 中运行 Docker: FROM ubuntu:16.04 RUN apt-get update && \ apt-get in
我尝试为 Docker 镜像定位一个特定标签。我怎样才能在命令行上做到这一点?我想避免下载所有图像,然后删除不需要的图像。 在 Ubuntu 官方版本中,https://registry.hub.do
我正在尝试在docker中运行docker。唯一的目的是实验性的,我绝不尝试实现任何功能,我只想检查docker从另一个docker运行时的性能。 我通过Mac上的boot2docker启动docke
docker-compose.yml version: "3" services: daggr: image: "docker.pvt.com/test/daggr:stable"
我有一个非常具体的开发环境用例。在一些代码中,我启动了一个容器来抓取页面并检索在容器中运行的服务(Gitlab)的 token 。 现在,我希望 Dockerize 运行它的代码。具体来说,类似: o
之前已经问过这个问题,但我不确定当时是否可以使用docker-compose文件完成docker堆栈部署。 由于最新版本支持使用compose将服务部署到堆栈,因此,我无法理解dab文件的值。 我检查
我在一次采访中被问到这个问题,但无法回答。也没有找到任何相关信息。 最佳答案 正如 Docker 文档中所述,Docker 注册表是: [...] a hosted service containin
有没有一种方法可以将具有给定扩展名的所有文件复制到Docker中的主机?就像是 docker cp container_name:path/to/file/in/docker/*.png path/o
我的日志驱动程序设置为journald。使用日志记录驱动程序时,daemon.json文件中的日志级别配置会影响日志吗?使用docker logs 时仅会影响容器日志? 例如,docker和journ
我最近开始使用Docker + Celery。我还共享了full sample codes for this example on github,以下是其中的一些代码段,以帮助解释我的观点。 就上下文
运行docker build .命令后,尝试提交构建的镜像,但收到以下错误 Step 12 : CMD activator run ---> Using cache ---> efc82ff1ca
我们有docker-compose.yml,其中包含Kafka,zookeeper和schema registry的配置 当我们启动docker compose时,出现以下错误 docker-comp
我是Docker的新手。是否可以在Docker Hub外部建立Docker基本镜像存储库?假设将它们存储在您的云中,而不是拥有DH帐户?谢谢。 最佳答案 您可以根据需要托管自己的注册表。可以在Depl
我是一名优秀的程序员,十分优秀!