赞
踩
新建文件夹Demo,在Demo中新建Dockerfile文件,输入以下内容:
# 官方镜像
FROM ubuntu:16.04
MAINTAINER WYD
# 替换源
RUN rm -rf /etc/apt/sources.list
ADD sources.list /etc/apt/
RUN apt-get update -y -q
RUN apt-get upgrade -y -q
在Demo中新建sources.list文件,输入以下内容:
由于国内更新和安装包的速度太慢,可以替换国内源加速更新和安装,这里使用阿里云的16.04版本源
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial universe deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties deb http://archive.canonical.com/ubuntu xenial partner deb-src http://archive.canonical.com/ubuntu xenial partner deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
docker build -t myubuntu:16.04 .
myubuntu是新生成的镜像名,16.04是tag .是在Demo下执行此命令
docker images
这样,就生成了最新的Ubuntu镜像,方便后边基于这个最新的镜像衍生其他的应用镜像。
新建文件夹Demo2,在Demo2中新建Dockerfile文件,输入以下内容:
#本地镜像
FROM myubuntu:16.04
MAINTAINER WYD
RUN apt-get install -y -q python3
RUN apt-get install -y -q python3-pip
RUN pip3 install django
WORKDIR /home
RUN rm -rf mysite
RUN django-admin.py startproject mysite
ADD run.sh /home/mysite/run.sh
WORKDIR /home/mysite
RUN chmod 777 run.sh
EXPOSE 8080
CMD ["/bin/sh","run.sh"]
新建文件夹Demo2,在Demo2中新建run.sh文件,输入以下内容:
python3 manage.py runserver 0.0.0.0:8080
docker build -t myubuntu:django .
执行结果
docker images
docker-machine ls
docker run -d -p 8088:8080 myubuntu:django
此时,docker的django服务已经在后台运行,可以在浏览器输入:192.168.99.100:8088进行访问
不要慌,接下来说这个问题。出现这样子,说明docker的端口映射已经成功,并且django已经正常运行。
docker ps
docker stop 1d59bcb80dae
docker run -it -p 8088:8080 myubuntu:django /bin/bash
没有安装vim,apt-get install vim 进行安装
编辑settings.py
vim的使用在此不多做讲述,wq保存退出
开启django服务
重新刷新192.168.00.100:8088:
容器修改成功。
exit退出容器
docker ps -a
docker commit -m "intall vim and fix django" aa9c3a3a21bd myubuntu:django
docker run -it -p 8088:8080 myubuntu:django /bin/sh /home/mysite/run.sh
crtl-c退出容器,查看容器id,并重新提交
docker commit -m "modify cmd" e5c6f7ea0e36 myubuntu:django
docker run -d -p 8088:8080 myubuntu:django
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。