1105471854403716
创建资源后生成收起
-
u-pswpk4qi@1105471854403716
-
Xk8Nv9Qg4Lv8Nu2D
-
LTAI5tJbLBnkb9xmbx9TVrgx
-
NR0GXcMrtxmcvDBfY5GhGm94beY3r5
注意:
若登录子账号,请打开隐私窗口进行登录。
ECS服务器
ECS公网地址:
106.14.82.59
ECS登录名:
root
登录密码:
Gd4Zt1Qc4E
ECS实例ID:
i-uf6glsufrrb9mmngcgym
IP白名单:
121.43.229.190,120.55.0.0/16,114.55.110.50,47.98.219.184,47.96.60.0/24,118.31.243.0/24,121.43.224.157,47.99.67.70,121.196.238.7,106.118.44.141
地域:
华东 2 (上海)
https://signin.aliyun.com/login.htm?username=u-pswpk4qi@1105471854403716
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast && yum -y install docker-ce
systemctl start docker
tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://registry.docker-cn.com"] } EOF
mkdir -p /tmp/demo && cd /tmp/demo
cat > /tmp/demo/main.go << EOF package main import ( "fmt" "net/http" ) func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello! World\n") }) fmt.Println("start to serve...") http.ListenAndServe(":80", nil) } EOF
cat > /tmp/demo/Dockerfile << EOF FROM golang:1.12-alpine # change current working dir WORKDIR /go/src/app # copy main.go into /go/src/app COPY . . # go build and install the app RUN go install -v ./... # run the app by default CMD ["app"] EOF
docker build . -t demo:v1
docker run -d -p 8000:80 demo:v1
- 参数-d设置容器运行模式为后台运行。
- 参数-p 8000:80将容器内部使用的网络端口映射到主机上,其中8000为主机端口,80为容器内部使用端口。
3. 使用curl工具访问容器中的HelloWorld服务。
curl localhost:8000
docker rm -f $(docker ps -a | grep "demo:v1" | awk '{print $1}')