DockerFile的学习

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创建连接

docker run -d -P --name web --link db:db training/webapp python app.py
  • –link name:alias
    name 是我们连接容器的名字,alias是link的别名。

Docker中运行Node.js web应用

  1. 创建空文件touch DockerFile
  2. 编辑文件
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]
  1. 创建你的镜像
sudo docker build -t <your username>/centos-node-hello
  1. 运行镜像
sudo docker run -p 49160:8080 -d <your username>/centos-node-hello

Docker 中运行MongoDB

  1. 创建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"]
  1. 构建MongoDB的Docker镜像
docker build --tag my/repo
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值