docker - 创建自己的image
访问量: 1102
参考: https://docs.docker.com/get-started/part2/
git clone https://github.com/dockersamples/node-bulletin-board
cd node-bulletin-board/bulletin-board-app
下载后,会发现有个 Dockerfile
$ cat Dockerfile FROM node:current-slim WORKDIR /usr/src/app COPY package.json . RUN npm install EXPOSE 8080 CMD [ "npm", "start" ] COPY . .
接下来,编译: (记得要先保证 sudo npm install 这个命令是可以运行的, 否则会失败. 见这个文章: http://siwei.me/blog/posts/nodejs-nvm-linux-sudo-npm-install
# docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0 Sending build context to Docker daemon 1.851MB Step 1/7 : FROM node:current-slim ---> 25b380aa6cdd Step 2/7 : WORKDIR /usr/src/app ---> Using cache ---> 957b70dc5292 Step 3/7 : COPY package.json . ---> e43e74a88cea Step 4/7 : RUN npm install ---> Running in 2eef6a10816a npm WARN deprecated [email protected]: Use pkg.json instead. added 166 packages, and audited 166 packages in 1m 2 packages are looking for funding run `npm fund` for details found 0 vulnerabilities npm notice npm notice New minor version of npm available! 7.0.14 -> 7.1.2 npm notice Changelog: npm notice Run `npm install -g [email protected]` to update! npm notice Removing intermediate container 2eef6a10816a ---> bb72b8cce8e8 Step 5/7 : EXPOSE 8080 ---> Running in b193438df59b Removing intermediate container b193438df59b ---> e1b4186c1a44 Step 6/7 : CMD [ "npm", "start" ] ---> Running in 8ecb0c5ac493 Removing intermediate container 8ecb0c5ac493 ---> 33fe4d654c93 Step 7/7 : COPY . . ---> e14b3c4f73f8 Successfully built e14b3c4f73f8 Successfully tagged bulletinboard:1.0
所以,接下来,我们开始创建:
1. 找一个基础版的操作系统,下载. 例如,我用的是ubuntu:
docker pull ubuntu
Using default tag: latest latest: Pulling from library/ubuntu da7391352a9b: Pull complete 14428a6d4bcd: Pull complete 2c2d948710f2: Pull complete Digest: sha256:c95a8e48bf88e9849f3e0f723d9f49fa12c5a00cfc6e60d2bc99d87555295e4c Status: Downloaded newer image for ubuntu:latest docker.io/library/ubuntu:latest
2. 运行这个image:
docker run -it ubuntu bash (-i, -t 分别表示: -i: interactive, -t: tty , 所以这里不能省略,否则 docker ps 不会有内容)
3. 就可以直接进入到 ubuntu环境下了, apt-get , apt-update 就可以直接使用了.