Skip to content

Instantly share code, notes, and snippets.

@jackiect
Last active May 13, 2016 03:10
Show Gist options
  • Save jackiect/18c54e81875e895902c5a642e11f53b1 to your computer and use it in GitHub Desktop.
Save jackiect/18c54e81875e895902c5a642e11f53b1 to your computer and use it in GitHub Desktop.
Docker搭建开发环境

Docker搭建开发环境

cache proxy

  • apt-cacher-server,针对命令apt-get install
  • devpi,针对pip install
  • nexus,针对mvn

apt-cacher-server

  1. docker build -t foundation/apt-cacher-ng:1.0.1 https://raw.githubusercontent.com/SvenDowideit/dockerfiles/4f8deb82ae9f78e95610cb8e49967384431e32b5/apt-cacher-ng/Dockerfile
  2. docker run --name apt-cacher-ng -d -p 3142:3142 -v :/var/cache/apt-cacher-ng foundation/apt-cacher-ng:1.0.1
  3. echo 'Acquire::http { Proxy "http://192.168.99.100:3142"; };' >> /etc/apt/apt.conf.d/01proxy,Client机修改配置
  4. apt-get install -y vim
  5. docker logs apt-cacher-ng命令后,看到类似如下日志,说明成功了
1460687180|I|952925|172.17.0.1|httpredir.debian.org/debian/pool/main/v/vim/vim_7.4.488-7_amd64.deb
1460687180|O|952892|172.17.0.1|httpredir.debian.org/debian/pool/main/v/vim/vim_7.4.488-7_amd64.deb
  1. TODO:如果apt-cacher-server停掉了会发生什么?

devpi

  1. docker pull scrapinghub/devpi
  2. docker run -d --name devpi -p 3141:3141 -v :/mnt scrapinghub/devpi
  3. Client机修改配置
# ~/.pip/pip.conf

[global]
index-url = http://192.168.99.100:3141/root/pypi/+simple/
[install]
trusted-host = 192.168.99.100
[search]
index = http://192.168.99.100:3141/root/pypi/

# ~/.pydistutils.cfg

[easy_install]
index-url = http://192.168.99.100:3141/root/pypi/+simple/
  1. TODO:如果devpi-server停掉了会发生什么?

PS: devpi镜像中不包含devpi-web,http://192.168.99.100:3141/root/pypi/并不能响应get的http请求

有如下Dockerfile构件的image tryenv

FROM ubuntu
ENV myEnv=v0.1
RUN mkdir $myEnv
RUN echo RUN has myEnv=${myEnv} >> run.txt
CMD echo $myEnv && echo CMD has myEnv=$myEnv >> cmd.txt && bash
  • docker run --name tryenv0 -itd tryenv, tryenv0中:日志第一行是v0.1;有文件夹v0.1;run.txt中的内容是RUN has myEnv=v0.1;cmd.txt内容CMD has myEnv=v0.1
  • docker run --name tryenv1 -itd --env myEnv=v0.1.1 tryenv, tryenv1中:日志第一行是v0.1.1;会有文件夹v0.1;run.txt中的内容是RUN has myEnv=v0.1;cmd.txt内容CMD has myEnv=v0.1.1

关于Docker Volume的几点

  1. Docker运行时,使用一种叫Union File System的文件系统概念。Union File System包含2层:从image中继承而来的可读(read-only)层,和处于最顶部的读-写(read-write)层
  2. volumes是处在Union File System文件系统之外的一层
  3. Docker运行时,一旦配置了volumes,会事实在主机文件系统映射本地文件/文件夹,container对volumes的数据读写将直接反映在主机文件系统中
  4. volumes和主机文件的映射只可能在运行时实行,而不可能在Dockerfile中实现这种映射关系;常用的实现是通过docker run命令的-v参数,或docker-compose.yml中配置
  5. 如果没有显示指定volume映射到主机的哪个文件/文件夹,docker在运行时会随机在主机新建一个文件夹与之映射;如果显示配置volumes映射关系,需要注意主机文件夹的读写权限问题
  6. Dockerfile中的VOLUMES是一种配置方式而不是实现方式,且是隐式配置方式,而且Dockerfile中只能隐式配置
  7. 不管怎样,可以通过命令docker inspect -f {{.Mounts}} <container-id/container-name>查看完整的映射

参考

http://container-solutions.com/understanding-volumes-docker/

@jackiect
Copy link
Author

jackiect commented May 12, 2016

dev-machine

Dockerfile

FROM ubuntu:14.04.4

WORKDIR /root

RUN apt-get update && apt-get install -y openssh-server git vim
RUN mkdir /var/run/sshd
RUN echo 'root:0000' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config

ENV APT_PROXY=http://mirrors.163.com/
ENV PIP_INDEX_URL=http://mirrors.aliyun.com/pypi/simple/
ENV PIP_TRUSTED_HOST=mirrors.aliyun.com
ENV PIP_INDEX=http://mirrors.aliyun.com/pypi/

RUN mkdir .ssh
ADD .jack-ssh/* /root/.ssh/
COPY .ubuntu-bash_aliases /root/.bash_aliases

RUN mkdir usb
VOLUME /var/log usb
EXPOSE 22 5000 8080

CMD echo 'Acquire::http { Proxy "$APT_PROXY"; };' >> /etc/apt/apt.conf.d/01proxy && service ssh restart && bash
# .ubuntu-bash_aliases --> .bash_aliases
alias cls='clear'
alias gst='clear && git status'
alias gl='git log --color --graph --pretty=format:'\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit --'
alias grm='git fetch && git rebase origin/master'
alias grd='git fetch && git rebase origin/dev'

@jackiect
Copy link
Author

jackiect commented May 12, 2016

@jackiect
Copy link
Author

isinstance(value, (tuple, list))

in python
url_for("/", filters=(1,2))

in ninja template
url_for("", filters=("v1", "v2")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment