一、安装docker(略)
二、换源
# 进入docker
cd /etc/docker
# 找到json文件,并编辑
vim daemon.json
# 替换
{"registry-mirrors": ["http://hub-mirror.c.163.com"] }
# 重启docker
sudo systemctl restart docker
三、拉取centos7的镜像
docker pull centos:centos7
四、查看
docker images
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-g8NRzCN0-1573123249582)(/Users/bobwang/Library/Application Support/typora-user-images/image-20191107125835569.png)]
五、启动
docker run -it --rm centos:centos7
# 启动后查看版本号
cat /etc/redhat-release
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-315k9bIj-1573123249584)(/Users/bobwang/Library/Application Support/typora-user-images/image-20191107130016390.png)]
六、安装依赖
yum update -y
yum -y groupinstall "Development tools"
#2
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel -y
七、安装nginx
1)前往用户根目录
>: cd ~
2)下载nginx1.13.7
>: wget http://nginx.org/download/nginx-1.13.7.tar.gz
# 没有wget就yum install wget
3)解压安装包
>: tar -xf nginx-1.13.7.tar.gz
4)进入目标文件
>: cd nginx-1.13.7
5)配置安装路径:/usr/local/nginx
>: ./configure --prefix=/usr/local/nginx
6)编译并安装
>: make && make install
#报错
src/os/unix/ngx_user.c: In function 'ngx_libc_crypt':
src/os/unix/ngx_user.c:26:7: error: 'struct crypt_data' has no member named 'current_salt'
cd.current_salt[0] = ~salt[0];
# 解决
7)建立软连接:终端命令 nginx
>: ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
8)删除安装包与文件:
>: rm -rf nginx-1.13.7
>: rm -rf nginx-1.13.7.tar.xz
# 此刻如果直接打包成镜像,则启动的时候需要加 -g "daemon of;"
## 构建命令
docker commit -a bobwang -m "nginx1.13.7 for centos7" 739295627e3b centos7ofnginx:1.0
# 启动
docker run -d -p 80:80 --name mynginx centos7ofnginx:1.0 nginx -g "daemon off;"
八、基于新构建的centos7ofnginx:1.0生成容器,进入构建python3
#1、 启动镜像
docker run -it <镜像id>
# 2、下载python3.6.8的
# 或者是将本地的压缩包传到容器内
docker cp Python-3.6.8.tar.xz 7c980d3fd082:/root
# 3、解压
tar -xJf Python-3.6.8.tar.xz
# 4、进入目标文件
cd Python-3.6.8
# 5、配置安装路径:/usr/local/python3
>: ./configure --enable-optimizations --prefix=/usr/local/python3
# 6、编译安装
make && make install
# 7、建立软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3
#8删除安装包与文件:
>: rm -rf Python-3.6.8
>: rm -rf Python-3.6.8.tar.xz
#9 换源
1)创建pip配置路径
>: mkdir ~/.pip
2)进入目录编辑配置文件:填入下方内容
cd ~/.pip && vim pip.conf
[global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors =true
mirrors =http://pypi.douban.com/simple/
trusted-host =pypi.douban.com
九、安装uwsgi
pip3 install uwsgi
十、安装项目需要的所有依赖环境
#将pip.txt从服务器传到容器内
docker cp requirement.txt <容器id>:/root
#pip3 安装
pip install -r pip.txt
十一、打包镜像
docker commit -a bobwang -m "faq_project_image" f09dbe03dbe7 centos7ofdialog:1.0