在docker上运行.net core程序

一、安装docker及镜像

1、在centos上安装docker,命令如下:

# yum install docker

2、让docker随机启动:

# service docker start
# chkconfig docker on

3、下载官方的centos镜像:

# docker pull centos

4、确认镜像已经获取:

# docker images centos

 

5、查询是否已有docker运行:

# docker ps

6、发现列表为空,运行docker:

#  docker run -i -t centos /usr/sbin/init

勘正了一个错误,原来docker run -i -t centos /bin/bash   这样运行centos会有一些问题

如上图红框所示,已进入docker环境。

7、重开一个命令窗口,再次查询:

# docker ps

 8、可进入已有的docker环境:

docker exec -ti fervent_aryabhata /bin/bash

 9、当执行exitmingling退出后,再次执行docker ps发现列表为空,这个时候需要带一个参数-a:

 10、运行其中的一个,提示错误:

11、重启并运行即可:

二、安装.net core,按照https://www.microsoft.com/net/core#linuxcentos步骤走即可,不再赘述。

三、安装supervisor

1、安装epel源

yum install epel-release

2、安装pip

yum install python-pip

3、安装supervisor

pip install  supervisor

4、配置开机自启动

cat > /usr/lib/systemd/system/supervisord.service << EOF
[Unit]
Description=Process Monitoring and Control Daemon
After=rc-local.service

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

5、创建supervisor的配置文件夹

mkdir -p /var/supervisor
mkdir -p /etc/supervisor/conf.d

6、supervisor配置

echo_supervisord_conf > /etc/supervisor/supervisord.conf

sed -i 's/^;port=.*$/port=\*:9001/g' /etc/supervisor/supervisord.conf
sed -i 's/^;\[inet_http_server\]/\[inet_http_server\]/g' /etc/supervisor/supervisord.conf
sed -i "/port=\*:9001/a\password=admin" /etc/supervisor/supervisord.conf
sed -i "/port=\*:9001/a\username=admin" /etc/supervisor/supervisord.conf
sed -i "/\[supervisorctl\]/a\password=admin" /etc/supervisor/supervisord.conf
sed -i "/\[supervisorctl\]/a\username=admin" /etc/supervisor/supervisord.conf
sed -i "/\[supervisorctl\]/a\serverurl=http://127.0.0.1:9001" /etc/supervisor/supervisord.conf
sed -i 's/^pidfile=.*$/pidfile=\/var\/supervisor\/supervisord.pid/g' /etc/supervisor/supervisord.conf
sed -i 's/^file=.*$/file=\/var\/supervisor\/supervisor.sock/g' /etc/supervisor/supervisord.conf

 

6、讲文件夹下所有的ini配置文件加载进来

cat >> /etc/supervisor/supervisord.conf <<EOF
[include]
files = /etc/supervisor/conf.d/*.ini
EOF

 

7、创建一个shell脚本,启动网站,内容如下:

#!/bin/bash
cd /apps/smsweb && dotnet Qka.SmsAndIPAddressQuery.dll &

 

8、增加改文件的可执行权限:

chmod 777 startweb.sh

9、配置该shell脚本到supervisor中:

cat > /etc/supervisor/conf.d/smsweb.ini <<EOF
[program:smsweb]
command = /apps/smsweb/startweb.sh run
autorestart=true
redirect_stderr = true
stdout_logfile = /apps/smsweb/logs.log
logfile_maxbytes = 10MB
user = root
EOF

10、重启supervisor服务:

service supervisord restart

 

posted @ 2017-05-17 16:47  focus-lei  阅读(...)  评论(... 编辑 收藏