0%

Qihoo360 Wayne的文件目录为/Development/wayne

运行bee run命令时,会遇到如下错误。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cd src/backend

bee run -runargs=apiserver
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v1.10.0
2019/08/10 08:17:53 WARN ▶ 0001 Running application outside of GOPATH
2019/08/10 08:17:53 INFO ▶ 0002 Using 'backend' as 'appname'
2019/08/10 08:17:53 INFO ▶ 0003 Initializing watcher...
Fetching https://goproxy.io/github.com/modern-go/reflect2/@v/list
Fetching https://goproxy.io/sigs.k8s.io/yaml/@v/list
Fetching https://goproxy.io/sigs.k8s.io/@v/list
Fetching https://goproxy.io/github.com/modern-go/@v/list
Fetching https://goproxy.io/github.com/@v/list
build github.com/Qihoo360/wayne/src/backend: cannot load github.com/modern-go/reflect2: cannot find module providing package github.com/modern-go/reflect2
2019/08/10 08:17:55 ERROR ▶ 0004 Failed to build the application: build github.com/Qihoo360/wayne/src/backend: cannot load github.com/modern-go/reflect2: cannot find module providing package github.com/modern-go/reflect2

解决方法,在终端先执行如下命令,以GO MODULE的方式加载包,即可以正常运行。

1
2
export GO111MODULE=on   // mac, linux
set $GO111MODULE=on // windows
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
bee run -runargs=apiserver
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v1.10.0
2019/08/10 08:19:26 WARN ▶ 0001 Running application outside of GOPATH
2019/08/10 08:19:26 INFO ▶ 0002 Using 'backend' as 'appname'
2019/08/10 08:19:26 INFO ▶ 0003 Initializing watcher...
Fetching https://goproxy.io/sigs.k8s.io/yaml/@v/list
Fetching https://goproxy.io/github.com/modern-go/reflect2/@v/list
2019/08/10 08:19:35 SUCCESS ▶ 0004 Built Successfully!
2019/08/10 08:19:35 INFO ▶ 0005 Restarting 'backend'...
2019/08/10 08:19:35 SUCCESS ▶ 0006 './backend' is running...
2019/08/10 08:19:35.057 [D] [db.go:75] Initialize database connection: ****:root@tcp(127.0.0.1:3306)/
2019/08/10 08:19:35.076 [I] [asm_amd64.s:1337] http server Running on http://:8080
2019/08/10 08:19:35.076 [I] [asm_amd64.s:1337] Admin server Running on :8088

如果有些包下载不了,还可以设置GOPROXY环境变量。

1
2
export GOPROXY=https://goproxy.io       // mac, linux
set $GOPROXY=on // windows

Docker在生产环境中的运用越来越多,已经非常成熟。这篇文章将从入门级操作视角,来讲解如何入门学习Docker。

下载Docker安装软件

Docker官网下载mac版本Docker软件。

目前的链接是:https://download.docker.com/mac/stable/Docker.dmg

双击Docker图标,运行程序。

运行docker version命令,出现如下Client和Server信息,表明安装成功了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
docker version
Client: Docker Engine - Community
Version: 18.09.2
API version: 1.39
Go version: go1.10.8
Git commit: 6247962
Built: Sun Feb 10 04:12:39 2019
OS/Arch: darwin/amd64
Experimental: false

Server: Docker Engine - Community
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 04:13:06 2019
OS/Arch: linux/amd64
Experimental: false

拉取镜像

执行命令docker pull hello-world

1
2
3
4
docker pull hello-world
Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request
canceled while waiting forconnection (Client.Timeout exceeded while awaiting headers)

出现上述网络不通的问题,所以要换成国内的镜像源。

我目前使用的阿里云的容器镜像服务。镜像加速器地址为:https://w3344f23.mirror.aliyuncs.com。每个登录用户都不相同。

在mac系统上任何栏点击Docker小图标,Preference -> Daemon -> Registry mirrors添加上述镜像url。重启Docker。

更换国内镜像后再次执行命令,就成功了

1
2
3
4
5
6
docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f
Status: Downloaded newer image for hello-world:latest

查看镜像

1
2
3
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest fce289e99eb9 6 months ago 1.84kB

运行镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

运行Nginx镜像

拉取镜像

1
2
3
4
5
6
7
8
docker pull hub.c.163.com/library/nginx
Using default tag: latest
latest: Pulling from library/nginx
5de4b4d551f8: Pull complete
d4b36a5e9443: Pull complete
0af1f0713557: Pull complete
Digest: sha256:f84932f738583e0169f94af9b2d5201be2dbacc1578de73b09a6dfaaa07801d6
Status: Downloaded newer image for hub.c.163.com/library/nginx:latest

运行镜像

1
2
docker run -d hub.c.163.com/library/nginx
89979036016d6d09b5cf072e4ad72069e83c0c19929d439233393d0610eefb89

查看运行的容器

1
2
3
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89979036016d hub.c.163.com/library/nginx "nginx -g 'daemon of…" 2 minutes ago Up 2 minutes 80/tcp epic_thompson

进入容器

容器就相当于一个虚拟机,我们进入到容器中看看。

1
2
docker exec -it 89979036016d bash
root@89979036016d:/#

执行ps命令

1
2
root@89979036016d:/# ps
bash: ps: command not found

命令找不到。

1
root@89979036016d:/# apt-get update && apt-get install procps

再次执行ps查看nginx进程是否启动成功。

1
2
3
4
5
6
root@89979036016d:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 08:13 ? 00:00:00 nginx: master process nginx -g daemon off;
nginx 7 1 0 08:13 ? 00:00:00 nginx: worker process
root 8 0 0 08:16 pts/0 00:00:00 bash
root 350 8 0 09:07 pts/0 00:00:00 ps -ef

设定端口转发

停止容器

1
docker stop 89979036016d

重新运行镜像

我们把主机8080端口的请求转发到容器内部的80端口,使用-p fromport:toport参数

1
2
docker run -d -p 8080:80 hub.c.163.com/library/nginx
38068e229ea71e29de8cf1992dded3520d2334122bfbdc145958788b48de563a

访问页面

http://localhost:8080

就能成功看到nginx的欢迎页面了。

npm 从5.2版开始,增加了 npx 命令。Node 自带 npm 模块,所以可以直接使用 npx 命令。如果没有安装就手动安装一下。

1
sudo npm install -g npx

当我运行

1
2
3
4
5
npx create-react-app my-app
npx: 91 安装成功,用时 9.606 秒
You are running Node 6.3.1.
Create React App requires Node 8 or higher.
Please update your version of Node.

提示需要更新node。

查看本机node版本

1
2
node -v
v6.3.1

清除node的cache

1
sudo npm cache clean -f

安装n工具

1
2
3
4
sudo npm install -g n
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
/usr/local/lib
└── n@4.1.0

安装最新版本的node

1
2
3
4
5
6
7
sudo n stable

install : node-v10.16.0
mkdir : /usr/local/n/versions/node/10.16.0
fetch : https://nodejs.org/dist/v10.16.0/node-v10.16.0-darwin-x64.tar.gz
################################################################################### 100.0%
installed : v10.16.0

再次查看本机node版本

1
2
node -v
v10.16.0

更新npm到最新版

1
2
3
4
5
6
sudo npm install npm@latest -g
Password:
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
+ npm@6.10.0
added 14 packages from 10 contributors, removed 5 packages and updated 17 packages in 6.962s

验证版本号

1
2
node -v
npm -v