Centos Docker使用:以天池Docker练习赛为例

1. Centos安装Docker

脚本安装

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

查看docker状态

systemctl start docker
docker info

输出:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.5
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc version: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.9.11-1.el7.elrepo.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 997.3MiB
 Name: beaming-walk-1.localdomain
 ID: BGV7:ZE6T:E6WN:MMV7:667Z:RIJL:MPO7:3SOJ:GNYA:YRVL:LMR6:52TT
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

2. Docker阿里云练习赛

比赛链接

(1)创建镜像仓库

https://cr.console.aliyun.com

详看 手把手教学 天池

(2)centos 登录天池镜像仓库

sudo docker login --username=17******** registry.cn-shenzhen.aliyuncs.com

输入密码。

(3)创建所需文件

  1. Dockerfile:
# Base Images
## 从天池基础镜像构建
FROM registry.cn-shanghai.aliyuncs.com/tcc-public/python:3

## 把当前文件夹里的文件构建到镜像的根目录下
ADD . /

## 指定默认工作目录为根目录(需要把run.sh和生成的结果文件都放在该文件夹下,提交后才能运行)
WORKDIR /

## 镜像启动后统一执行 sh run.sh
CMD ["sh", "run.sh"]
  1. run.sh 文件

#!/bin/sh
CURDIR="`dirname $0`" #脚本目录
echo $CURDIR
cd $CURDIR #切换目录
python submit_v1.py

  1. python程序 submit_v1.py

#coding:utf-8
#!/usr/bin/env python

import json
import heapq

data = {}
data["Q1"] = "Hello world"
# Q2
sum_q2 = 0
data_list = []
with open("./tcdata/num_list.csv", "r", encoding="utf-8") as f:
        for line in f:
                sum_q2 += int(line.strip())
                data_list.append(int(line.strip()))

data["Q2"] = sum_q2
#
top10_list = heapq.nlargest(10, data_list)
data["Q3"] = top10_list
with open("result.json", "w", encoding="utf-8") as f:
        json.dump(data, f)

  1. 运行docker
docker build -t registry.cn-shenzhen.aliyuncs.com/docker_test_rosefun/test_for_tianchi:1.0 .

注意:后面是有一个点,代表输出到本地文件夹。

  1. 上传docker
docker push registry.cn-shenzhen.aliyuncs.com/docker_test_rosefun/test_for_tianchi:1.0
  1. 天池提交结果
    在这里插入图片描述

  2. 查看分数

在这里插入图片描述

相关推荐
©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页