Open jackieli123723 opened 6 years ago
首先升级一下系统包 (可以跳过) $ sudo yum update
卸载旧版本的 Docker $ sudo yum erase docker docker-common docker-client docker-compose
添加 Docker 的 yum 源 创建一个 /etc/yum.repos.d/docker.repo 文件,内容如下:
[dockerrepo] name=Docker Repository baseurl=https://yum.dockerproject.org/repo/main/centos/7/ enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg
安装新版本 Docker $ sudo yum install -y docker-engine
安装完后设置为系统开机自动启动服务
$ sudo systemctl enable docker.service
启动服务
$ sudo systemctl start docker
测试一下
docker info
[root@instance-7aqka2xd default]# docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[root@instance-7aqka2xd run]# docker info
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
或
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.错误1
使用
Remove /var/lib/docker (rm -rf /var/lib/docker). Restart Docker solved the problem.
效果
[root@instance-7aqka2xd run]# rm -rf /var/lib/docker
[root@instance-7aqka2xd run]# service docker start
Redirecting to /bin/systemctl start docker.service
[root@instance-7aqka2xd run]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@instance-7aqka2xd home]# docker --version
Docker version 17.05.0-ce, build 89658be
[root@instance-7aqka2xd ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: jackieli123456
Password:
Login Succeeded
[root@instance-7aqka2xd ~]#
[root@instance-7aqka2xd node-docker]# cd hello-vue/
[root@instance-7aqka2xd hello-vue]# ll
total 12
-rw-r--r-- 1 root root 171 May 2 19:58 Dockerfile
-rw-r--r-- 1 root root 196 Apr 27 10:06 index.js
-rw-r--r-- 1 root root 281 May 2 16:50 package.json
[root@instance-7aqka2xd hello-vue]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-node-server_my-node-server latest 1367fc30f732 3 hours ago 431MB
my-node-server latest ecffa79c850d 3 hours ago 431MB
hello-vue2 latest dcc402f6640c 18 hours ago 678MB
hello-vue latest 07fa74b8a462 19 hours ago 678MB
demo latest 7cf2a0467b7b 19 hours ago 675MB
registry.docker-cn.com/library/ubuntu latest 452a96d81c30 5 days ago 79.6MB
registry.docker-cn.com/library/node latest 26cbfbc03e3f 5 days ago 675MB
registry.docker-cn.com/library/node carbon 4635bc7d130c 4 weeks ago 672MB
[root@instance-7aqka2xd hello-vue]# docker build -t jackieli123456/hello-vue .
Sending build context to Docker daemon 4.096kB
Step 1/7 : FROM registry.docker-cn.com/library/node
---> 26cbfbc03e3f
Step 2/7 : WORKDIR /app
---> Using cache
---> f8fe5a9f7002
Step 3/7 : COPY package.json /app
---> Using cache
---> 13b20def19ce
Step 4/7 : RUN npm install
---> Using cache
---> 1a336a453a2a
Step 5/7 : COPY . /app
---> Using cache
---> 1a5c8907d30b
Step 6/7 : CMD npm start
---> Using cache
---> 12c49a785d19
Step 7/7 : EXPOSE 8082
---> Using cache
---> dcc402f6640c
Successfully built dcc402f6640c
Successfully tagged jackieli123456/hello-vue:latest
[root@instance-7aqka2xd hello-vue]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-node-server_my-node-server latest 1367fc30f732 3 hours ago 431MB
my-node-server latest ecffa79c850d 3 hours ago 431MB
jackieli123456/hello-vue latest dcc402f6640c 18 hours ago 678MB
hello-vue2 latest dcc402f6640c 18 hours ago 678MB
hello-vue latest 07fa74b8a462 19 hours ago 678MB
demo latest 7cf2a0467b7b 19 hours ago 675MB
registry.docker-cn.com/library/ubuntu latest 452a96d81c30 5 days ago 79.6MB
registry.docker-cn.com/library/node latest 26cbfbc03e3f 5 days ago 675MB
registry.docker-cn.com/library/node carbon 4635bc7d130c 4 weeks ago 672MB
[root@instance-7aqka2xd hello-vue]# docker push jackieli123456/hello-vue:latest
The push refers to a repository [docker.io/jackieli123456/hello-vue]
341ffb164d92: Pushed
5f8e08491715: Pushed
d32c0e689a72: Pushed
63c722598511: Pushed
bda9895de7e8: Pushed
3d5c4fdcdf7f: Pushed
33aed7748ee3: Pushed
0e0b4ee1c6dc: Pushed
ff57bdb79ac8: Pushed
6e5e20cbf4a7: Pushed
86985c679800: Pushed
8fad67424c4e: Pushed
latest: digest: sha256:88389a44d230c90058bcb1926d0be1ec490d518bb02ef2ec15297a63cbf1f0e9 size: 2838
[root@instance-7aqka2xd hello-vue]#
FROM registry.docker-cn.com/library/node
docker pull jackieli123456/hello-vue (官方)
docker pull registry.docker-cn.com/jackieli123456/hello-vue (中国镜像)
[root@instance-7aqka2xd hello-vue]# docker pull registry.docker-cn.com/jackieli123456/hello-vue
Using default tag: latest
latest: Pulling from jackieli123456/hello-vue
Digest: sha256:88389a44d230c90058bcb1926d0be1ec490d518bb02ef2ec15297a63cbf1f0e9
Status: Downloaded newer image for registry.docker-cn.com/jackieli123456/hello-vue:latest
[root@instance-7aqka2xd hello-vue]# docker pull jackieli123456/hello-vue
Using default tag: latest
latest: Pulling from jackieli123456/hello-vue
Digest: sha256:88389a44d230c90058bcb1926d0be1ec490d518bb02ef2ec15297a63cbf1f0e9
Status: Downloaded newer image for jackieli123456/hello-vue:latest
[root@instance-7aqka2xd hello-vue]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-node-server_my-node-server latest 1367fc30f732 4 hours ago 431MB
my-node-server latest ecffa79c850d 4 hours ago 431MB
jackieli123456/hello-vue latest dcc402f6640c 19 hours ago 678MB
hello-vue2 latest dcc402f6640c 19 hours ago 678MB
registry.docker-cn.com/jackieli123456/hello-vue latest dcc402f6640c 19 hours ago 678MB
hello-vue latest 07fa74b8a462 20 hours ago 678MB
demo latest 7cf2a0467b7b 20 hours ago 675MB
registry.docker-cn.com/library/ubuntu latest 452a96d81c30 5 days ago 79.6MB
registry.docker-cn.com/library/node latest 26cbfbc03e3f 5 days ago 675MB
registry.docker-cn.com/library/node carbon 4635bc7d130c 4 weeks ago 672MB
[root@instance-7aqka2xd hello-vue]#
docker 构建node微服务
Docker version 17.05.0-ce, build 89658be(基于该版本的构建) [root@instance-7aqka2xd hello-vue]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) [root@instance-7aqka2xd hello-vue]# docker --version Docker version 17.05.0-ce, build 89658be
版本太低的话会导致如下问题:
例如:docker 1.13.1版本
docker build 的时候 step 走不完
生成none 的镜像
还有就是各种bug问题
服务启动不了等等
(是docker版本的问题 坑啊啊坑!!!!!!!!!!!!!!) (升级到最新的就好)
项目结构的源码
构建镜像
docker 镜像列表
创建docker 容器
通过镜像可启动多个
docker 停止容器
docker 重启容器
docker 改为npm script 命令可切换dev/qa/prod变量打包上线容器部署
进入不同容器containerID