# Set the base image to Ubuntu
FROM ubuntu
# File Author / Maintainer
MAINTAINER Anand Mani Sankar
# Update the repository and install Redis Server
RUN apt-get update && apt-get install -y redis-server
# Expose Redis port 6379
EXPOSE 6379
# Run Redis Server
ENTRYPOINT [“/usr/bin/redis-server"]
# Set the base image to Ubuntu
FROM ubuntu
# File Author / Maintainer
MAINTAINER Anand Mani Sankar
# Update the repository
RUN apt-get update
# Install Node.js and other dependencies
RUN apt-get -y install curl
RUN curl -sL https://deb.nodesource.com/setup | sudo bash -
RUN apt-get -y install python build-essential nodejs
# Install nodemon
RUN npm install -g nodemon
# Bundle app source
COPY . /src
# Install app dependencies
RUN cd /src; npm install
# Expose port
EXPOSE 8080
# Run app using nodemon
CMD ["nodemon", “/src/index.js"]
上面的Dockerfile解释如下:
从Docker Hub拉取Ubuntu基础镜像
使用apt-get安装Node.js以及依赖
使用npm安装nodemon
从host目录复制应用源码到容器内 src
运行 npm install 安装Node应用依赖
端口8080从容器抛出,使用nodemon运行应用
使用Dockerfile构建一个Docker镜像:
docker build -t msanand/node .
从自定义镜像中创建一个Node容器并连接Redis容器:
docker run -d --name node -p 8080 --link redis:redis msanand/node
# Set nginx base image
FROM nginx
# File Author / Maintainer
MAINTAINER Anand Mani Sankar
# Copy custom configuration file from the current directory
COPY nginx.conf /etc/nginx/nginx.conf
构建Docker镜像:
docker build -t msanand/nginx .
从镜像中创建一个Nginx容器,并连接到Node容器:
docker run -d --name nginx -p 80:80 --link node:node msanand/nginx
# Set the base image to Ubuntu
FROM ubuntu
# File Author / Maintainer
MAINTAINER Anand Mani Sankar
# Install Nginx
# Add application repository URL to the default sources
# RUN echo "deb http://archive.ubuntu.com/ubuntu/ raring main universe" >> /etc/apt/sources.list
# Update the repository
RUN apt-get update
# Install necessary tools
RUN apt-get install -y nano wget dialog net-tools
# Download and Install Nginx
RUN apt-get install -y nginx
# Remove the default Nginx configuration file
RUN rm -v /etc/nginx/nginx.conf
# Copy a configuration file from the current directory
ADD nginx.conf /etc/nginx/
# Append "daemon off;" to the configuration file
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# Expose ports
EXPOSE 80
# Set the default command to execute when creating a new container
CMD service nginx start