CentOS 6.5安装Docker并创建ASP.NET MVC 5 镜像,运行MVC 网站
Docker,容器,让研发、测试、生产同一环境,可在Linux平台上混合使用Java与.net 程序
rpm -ivh http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
yum -y install docker-io
service docker start
chkconfig docker on
安装asp.net mvc5镜像请参考http://dockerone.com/article/164
但是这个教程做出来的镜像只能跑个小DEMO,用MVC代码则会报引用错误,应该要参考其中提到的https://registry.hub.docker.com/u/microsoft/aspnet/
结合二者最终的Dockerfile如下
FROM mono:3.10
ENV KRE_VERSION 1.0.0-beta2
ENV KRE_USER_HOME /opt/kre
RUN apt-get -qq update && apt-get -qqy install unzip
RUN curl -sSL https://raw.githubusercontent.com/aspnet/Home/v$KRE_VERSION/kvminstall.sh | sh
RUN bash -c "source $KRE_USER_HOME/kvm/kvm.sh \
&& kvm install $KRE_VERSION -a default \
&& kvm alias default | xargs -i ln -s $KRE_USER_HOME/packages/{} $KRE_USER_HOME/packages/default"
# Install libuv for Kestrel from source code (binary is not in wheezy and one in jessie is still too old)
RUN apt-get -qqy install \
autoconf \
automake \
build-essential \
libtool
RUN LIBUV_VERSION=1.0.0-rc2 \
&& curl -sSL https://github.com/joyent/libuv/archive/v${LIBUV_VERSION}.tar.gz | tar zxfv - -C /usr/local/src \
&& cd /usr/local/src/libuv-$LIBUV_VERSION \
&& sh autogen.sh && ./configure && make && make install \
&& rm -rf /usr/local/src/libuv-$LIBUV_VERSION \
&& ldconfig
ENV PATH $PATH:$KRE_USER_HOME/packages/default/bin
COPY . /app
WORKDIR /app
RUN ["kpm", "restore"]
EXPOSE 5004
ENTRYPOINT ["k", "kestrel"]
以下生成镜像并启动
docker build -t mvc .
docker run -t -d -p 80:5004 mvc
其它相关命令
docker ps
docker stop
docker images
docker rmi
所需要的DEMO代码在
https://github.com/aspnet/Home/
执行效果图
更多Docker相关教程见以下内容:
Docker 的详细介绍:请点这里
Docker 的下载地址:请点这里