Docker搭建开发环境
-
-
Save jackiect/18c54e81875e895902c5a642e11f53b1 to your computer and use it in GitHub Desktop.
Docker搭建开发环境
- apt-cacher-server,针对命令
apt-get install
- devpi,针对
pip install
- nexus,针对
mvn
docker build -t foundation/apt-cacher-ng:1.0.1 https://raw.githubusercontent.com/SvenDowideit/dockerfiles/4f8deb82ae9f78e95610cb8e49967384431e32b5/apt-cacher-ng/Dockerfile
docker run --name apt-cacher-ng -d -p 3142:3142 -v :/var/cache/apt-cacher-ng foundation/apt-cacher-ng:1.0.1
echo 'Acquire::http { Proxy "http://192.168.99.100:3142"; };' >> /etc/apt/apt.conf.d/01proxy
,Client机修改配置apt-get install -y vim
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
- TODO:如果apt-cacher-server停掉了会发生什么?
docker pull scrapinghub/devpi
docker run -d --name devpi -p 3141:3141 -v :/mnt scrapinghub/devpi
- 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/
- 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运行时,使用一种叫Union File System的文件系统概念。Union File System包含2层:从image中继承而来的可读(read-only)层,和处于最顶部的读-写(read-write)层
- volumes是处在Union File System文件系统之外的一层
- Docker运行时,一旦配置了volumes,会事实在主机文件系统映射本地文件/文件夹,container对volumes的数据读写将直接反映在主机文件系统中
- volumes和主机文件的映射只可能在运行时实行,而不可能在
Dockerfile
中实现这种映射关系;常用的实现是通过docker run
命令的-v
参数,或docker-compose.yml
中配置 - 如果没有显示指定volume映射到主机的哪个文件/文件夹,docker在运行时会随机在主机新建一个文件夹与之映射;如果显示配置volumes映射关系,需要注意主机文件夹的读写权限问题
Dockerfile
中的VOLUMES
是一种配置方式而不是实现方式,且是隐式配置方式,而且Dockerfile中只能隐式配置- 不管怎样,可以通过命令
docker inspect -f {{.Mounts}} <container-id/container-name>
查看完整的映射
http://container-solutions.com/understanding-volumes-docker/
ubuntu docker 搭建python开发环境
apt-get update
apt-get install -y vim curl
apt-get install -y python-dev python-pip build-essential
pip install virtualenv
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'
- alias apt-get='apt-get -o Acquire::http::proxy="http://mirrors.163.com/"' ## 搜狐源http://mirrors.sohu.com/ http://192.168.99.100:3142/
https://pypi.doubanio.com/simple/
http://mirrors.aliyun.com/pypi/simple/
http://192.168.99.100:3141/root/pypi/+simple/
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
cache proxy
apt-get install
pip install
mvn
apt-cacher-server
docker build -t foundation/apt-cacher-ng:1.0.1 https://raw.githubusercontent.com/SvenDowideit/dockerfiles/4f8deb82ae9f78e95610cb8e49967384431e32b5/apt-cacher-ng/Dockerfile
docker run --name apt-cacher-ng -d -p 3142:3142 -v :/var/cache/apt-cacher-ng foundation/apt-cacher-ng:1.0.1
或 通过命令行参数alias apt-get='apt-get -o Acquire::http::proxy="http://mirrors.163.com/"'
echo 'Acquire::http { Proxy "http://192.168.99.100:3142"; };' >> /etc/apt/apt.conf.d/01proxy
,Client机修改配置apt-get install -y vim
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
devpi
docker pull scrapinghub/devpi
docker run -d --name devpi -p 3141:3141 -v :/mnt scrapinghub/devpi
Client机修改配置
或设置PIP_前缀的环境变量
PS: devpi镜像中不包含devpi-web,http://192.168.99.100:3141/root/pypi/并不能响应get的http请求