DockerFile的学习
最近因为项目的原因,我准备复习一下dockerfile,虽然网上说docker已经快凉凉了。不过它这种部署的方式,还是蛮好的,特别适合像我这样在一个服务器上面需要部署很多服务的。
新建一个Dockerfile
#This is a comment
FROM ubuntu:14.04
MAINTAINER wubingyu<flybetter@163.com>
RUN apt-get -qq update
RUN apt-get -qqy install ruby ruby-dev
RUN gem install sinatra
- 每个指令前缀都必须大写:INSTRUCTION statement
- 可以使用#注释
link
使用–link创建连接
docker run -d -P --name web --link db:db training/webapp python app.py
- –link name:alias
name 是我们连接容器的名字,alias是link的别名。
Docker中运行Node.js web应用
- 创建空文件
touch DockerFile
- 编辑文件
FROM centos:6.4
# Enable EPEL for Node.js
RUN rpm -Uvh“http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm”
#Install Node.js and npm
RUN yum install -y npm
#Bundle app source
ADD ./SRC
#Install app dependencies
RUN cd /src;npm install
EXPOSE 8080
CMD ["node","/src/index.js]
- 创建你的镜像
sudo docker build -t <your username>/centos-node-hello
- 运行镜像
sudo docker run -p 49160:8080 -d <your username>/centos-node-hello
Docker 中运行MongoDB
- 创建DockerFile
# Dockerizing MongoDB:Dockerfile for building MongoDB images
# Based on ubuntu:latest,installs MongoDB following the instructions from
# https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
# Format:FROM repository[:version]
From ubuntu:latest
# Format:MAINTAIN Name<>
MAINTAINER wubingyu<flybetter@163.com>
“# Installation:
# Import MongoDB public GPG key AND create a MongoDB list file
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
RUN echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/10gen.list”
# Update apt-get sources AND install MongoDB
RUN apt-get update
RUN apt-get install -y -q mongodb-org
# Create the MongoDB data directory
RUN mkdir -p /data/db
# Expose port 27017 from the container to the host
EXPOSE 27017
#Set usr/bin/mongod as the dockerized entry-point application
ENTRYPOINT ["usr/bin/mongod"]
- 构建MongoDB的Docker镜像
docker build --tag my/repo