美文网首页
docker从images部署django项目

docker从images部署django项目

作者: 无为法 | 来源:发表于2019-01-08 13:44 被阅读0次

    STEP1. image --> container

    docker load < xxx.tar

    docker run -dit --privileged <image id> /usr/sbin/init

    STEP2. 开启端口映射

    # 假设container内主机地址为172.16.0.3,我们要将ssh-server端口(22-->22222)和django-server端口(8000-->8088)映射出来

    iptables -t nat -A DOCKER -p tcp --dport 22222 -j DNAT --to-destination 172.17.0.3:22

    iptables -t nat -A DOCKER -p tcp --dport 8088 -j DNAT --to-destination 172.17.0.3:8000

    iptables -t nat -A POSTROUTING -j MASQUERADE -p tcp --source 172.17.0.3 --destination 172.17.0.3 --dport 22

    iptables -t nat -A POSTROUTING -j MASQUERADE -p tcp --source 172.17.0.3 --destination 172.17.0.3 --dport 8000

    iptables -A DOCKER -j ACCEPT -p tcp --destination 172.17.0.3 --dport 22

    iptables -A DOCKER -j ACCEPT -p tcp --destination 172.17.0.3 --dport 8000

    STEP3. ssh连接container主机

    # 先验证是否映射成功(假设外网ip是:x.x.x.x 端口是123)

    windows系统:打开cmd窗口输入命令:telnet x.x.x.x 123

    linux系统:输入命令:wget x.x.x.x:123

    # 映射成功后登录主机上传项目文件

    打开secureCRT连接上container主机后, 按alt + p进入sftp界面上传文件:put -r xxx

    相关文章

      网友评论

          本文标题:docker从images部署django项目

          本文链接:https://www.haomeiwen.com/subject/ijxvrqtx.html