1.拉取最近的centos镜像:
docker pull centos

2.跑一个容器:
docker run -itd --privileged --name centos_as2 -v /home/furuiyang/async:/home/furuiyang/async centos /usr/sbin/init

3.进入容器中:
docker exec -it centos_as2 /bin/bash

4.安装过程:
yum install wget
cd /usr/local/src
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py install

cd /usr/local/src
wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
tar -zxvf pip-9.0.1.tar.gz
cd pip-9.0.1
python setup.py build
python setup.py install
pip -V # 查看安装是否成功

cd /usr/local/src
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
tar -zxvf Python-3.6.4.tgz
cd Python-3.6.4/
yum install gcc
cd /usr/local
mkdir python3
./configure --with-ssl --prefix=/usr/local/python3 # 首先创建 python3 文件夹

yum -y install zlib*
yum -y install gcc automake autoconf libtool make
make && make install

rm -rf /usr/bin/python
ln -s /usr/local/python3/bin/python3 /usr/bin/python

vi /usr/bin/yum # 删除了旧版本的依赖之后 yum无法使用,这两个文件开头的python改为python2.7即可
vi /usr/libexec/urlgrabber-ext-down

yum install mysql
yum install mysql-server(不能成功)
yum install mysql-devel

cd /usr/local/src
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server
systemctl status mysqld # 查看mysql服务状态
systemctl start mysqld # 开启服务

curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz
tar -zxvf mongodb-linux-x86_64-3.0.6.tgz # 解压
mv mongodb-linux-x86_64-3.0.6/ /usr/local/mongodb # 将解压包拷贝到指定目录
mkdir -p /data/db

alabaster # 使用 pip 安装所需要的包,ssl无法使用就重新编译 ./configure --with-ssl --prefix=/usr/local/python3
APScheduler
Babel
docutils
imagesize
Jinja2
lxml
MarkupSafe
mysql-replication
Pygments
pymongo
PyMySQL
pytz
setproctitle
six
snowballstemmer
Sphinx
tzlocal

导入本地语言包:
vim ~/.bash_profile
export LANG=en_US.UTF-8 # 添加这行
source ~/.bash_profile
locale # 检查

删除无用的压缩包:

安装 ssh:
yum -y install openssh-clients

安装 service:
yum list | grep initscripts
yum install initscripts -y

后台ssh mongodb数据库:
ssh -N -L 27017:127.0.0.1:27017 -p 9528 furuiyang@139.159.148.58 -f

后台运行程序:
docker exec -d centos_as2 python /home/furuiyang/async/mymongo/myreplicator.py --mysqldump-data &

使用 Dockerfile 生成

# 基础镜像
FROM centos

# 时区设置
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
  && echo 'Asia/Shanghai' >/etc/timezone \

# 设置系统语言为中文
RUN yum -y install net-tools wget lrzsz kde-l10n-Chinese glibc-common
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8
ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8

# gcc 编译
RUN yum update -y \
    && yum install -y https://centos7.iuscommunity.org/ius-release.rpm \
    && yum install -y python36u python36u-libs python36u-devel python36u-pip \
    && yum install -y which gcc \
    && yum install -y openldap-devel

# 安装上传服务相关
RUN yum install lrzsz -y \
    && yum install zip -y \
    && yum install unzip -y

# pipenv
RUN pip3.6 install pipenv
RUN ln -s /usr/bin/pip3.6 /bin/pip
RUN rm /usr/bin/python
RUN ln -s /usr/bin/python3.6 /usr/bin/python

# 设置当前的工作目录
WORKDIR /home/furuiyang/async/

# 拷贝 requirements.txt
COPY requirements.txt  ./

# 安装依赖
RUN pip install -r requirements.txt

构建

docker build -t asmongo:v1 .
docker run --name asc1 -itd -v /home/furuiyang/async:/home/furuiyang/async asmongo:v1
docker exec -it asc1 /bin/bash

更新于 2019.6.20
如果语言环境出现问题,可以注释掉 设置系统语言为中文 的部分, 并且在 py 文件的开头设置

	# -*- coding: utf-8 -*-
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐