Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

了解Docker, 以及相关的前景 #2

Open
iannono opened this issue Jan 13, 2016 · 4 comments
Open

了解Docker, 以及相关的前景 #2

iannono opened this issue Jan 13, 2016 · 4 comments

Comments

@iannono
Copy link
Member

iannono commented Jan 13, 2016

https://www.docker.com

@caok
Copy link
Member

caok commented Jan 13, 2016

@iannono
Copy link
Member Author

iannono commented Jan 14, 2016

@iannono
Copy link
Member Author

iannono commented Apr 21, 2016

如何利用docker搭建rails的运行环境
https://robots.thoughtbot.com/rails-on-docker

为什么要使用docker
http://dockone.io/article/73

使用docker的服务:
https://www.shurenyun.com/price

native docker:
http://dockone.io/article/1214

Q: image 和 container 的关系还是没弄明白, container是从image里面取所需要的内容来创建一个运行环境吗?

docker 教程

概念介绍
https://app.pluralsight.com/library/courses/docker-containers-big-picture/table-of-contents
实战
https://app.pluralsight.com/library/courses/docker-web-development/table-of-contents

对比VMware

screen shot 2016-04-21 at 17 43 27

docker 相关软件

https://www.docker.com/products/docker-toolbox

安装和运行基础步骤

brew install caskroom/cask/brew-cask
brew cask install virtualbox
brew install docker docker-machine
docker-machine create --driver virtualbox default
eval "$(docker-machine env default)"

docker-machine start
docker-machine env default

add to .zshrc
eval `docker-machine env 2>/dev/null`

brew install docker-compose

docker build .

docker-compose run web rake db:create db:setup
docker-machine ip default
docker-compose up

@iannono
Copy link
Member Author

iannono commented Apr 22, 2016

:docker-machine

docker-machine是用来与虚拟机进行交互, 包括启动, 暂停, 设置虚拟机环境等.
这其中的虚拟机就包括本地的机器环境和云端的机器环境

# 查看当前机器上可用的虚拟机(假设当前虚拟机的名字为default)
docker-machine ls
docker-machine ip default
docker-machine status default
docker-machine stop default
docker-machine start default


# 如果不是通过docker terminal启动, 如何配置docker
# 检查当前的docker是否正常运行
docker ps
# 查看default的环境配置
docker-machine env default

# 通过docker-client 与docker engine进行交互
# 配置image 和 container
docker pull [image name]
docker run [image name]
docker images
docker ps

# 抓取一个image 并运行
docker pull hello-world
docker run hello-world
# 查看所有的container
docker ps -a
docker stop [container id]
docker rm [container id]
docker rmi [image id]


# 抓取nginximage
docker pull kitematic/hello-world-nginx
# 前一个80代表了vm的端口, 后一个80代表container的端口
docker run -p 80:80 kitematic/hello-world-nginx

# 如何将source coder放入container
1. 创建一个container volume并指向source code
valume 是container中的一种特殊的文件目录类型
并能够在container间共享和重用
更新image不会影响volume
删除container也不会影响volume
2. 添加source code到custom image, 以便用于创建一个container

# 创建一个volume(-v 代表创建一个volume, 后接的参数是container volume, pwd代表host location)
docker run -p 8080:3000 -v /var/www node
docker run -p 8080:3000 -v $(pwd):/var/www node
docker inspect mycontainer
# 同时删除掉volume
docker rm -v [container id]

# example for volume(在node image中运行express)
docker run -p 8080:3000 -v $(pwd):/var/www -w "/var/www" node npm start


# docker file
FROM [image name]:[version]

# example
FROM node:latest
MAINTAINER Ian

ENV NODE_ENV=production
ENV PORT=3000

COPY . /var/www
WORKDIR /var/www

RUN npm install
EXPOSE $PORT
ENTRYPOINT ["npm", "start"]

# use docker file to build a custom image
docker build [-f Dockerfile] -t <your username(tag name)>/node .

# push image to docker hub
docker login
docker push <your username>/node


# linking container by name
docker run -d --name my-postgres postgres
docker run -d -p 5000:5000 --link my-postgres:postgres(linked container alias) <username>/node

example:
docker build -f node.dockfile -t <username>/node .
docker run -d --name my-mongodb mongo
docker run -d -p 5000:5000 --link my-mongodb:mongo <username>/node

docker exec [container id] command

# container network
docker network create --driver bridge isolated_network
docker run -d --net=isolated_network --name mongodb mongo

# docker compose
docker-compose build
docker-compose up
docker-compose down
docker-compose down --rmi all --volumes
docker-compose logs
docker-compose ps
docker-compose stop
docker-compose start
docker-compose rm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants