-
移除所有的容器和镜像
sudo docker kill $(sudo docker ps -q) sudo docker rm $(sudo docker ps -a -q) sudo docker rmi $(sudo docker images -q -a)
-
检测docker镜像或者容器的基本信息
docker inspect [--help] [-f|--format[=FORMAT]] CONTAINER|IMAGE [CONTAINER|IMAGE...]
-
编写Dockerfile生成image
docker build <path>
寻找path路径下名为的Dockerfile的配置文件,使用此配置生成新的image
-
保存修改的容器
sudo docker commit -m "Added python-pip tailer" -a "Docker Newbee" 0b2616b0e5a8 myrepo/gr:v2
其中,-m 来指定提交的说明信息,跟我们使用的版本控制工具一样;-a 可以指定更新的用户信息;之后是用来创建镜像的容器的 ID;最后指定目标镜像的仓库名和 tag 信息。创建成功后会返回这个镜像的 ID 信息。
-
删除所有none的镜像
sudo docker images | grep none |awk '{print $3}'|xargs sudo docker rmi
-
在docker中调用docker
sudo docker run --rm -t -i -p 8889:8889 -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):$(which docker) b0e77ef5cfd7
-
数据卷容器的使用
-
创建一个数据卷容器
sudo docker create -v /dbdata --name dbdata training/postgres /bin/true sudo docker run -ti --volumes-from dbdata -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):$(which docker) b0e77ef5cfd7 sudo docker run --rm --volumes-from dbdata garland/butterfly g++ /dbdata/test.cpp -o /dbdata/test sudo docker run -t -i -p 8889:8889 --volumes-from dbdata -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):$(which docker) nikefd/tjide2
-
数据库连接
sudo docker run -v ~/workplace/test/mysql:/var/lib/mysql -d --name mysql -e MYSQL_ROOT_PASSWORD=admin nikefd/mysql sudo docker exec -it mysql bash sudo docker run --rm -ti -v ~/workplace/userdata:/userdata -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):$(which docker) -v ~/workplace/graduation-project:/try --link mysql:tomysql --name tjide0 -p 8000:8888 nikefd/tjide sudo docker run --link tjide0:to0 --link tjide1:to1 --name nginx -p 80:80 -d nikefd/nginx sudo docker exec -ti nginx bash
Step 1: run the program in a docker
-
Download the image ubuntu
sudo docker pull ubuntu vi Dockerfile
-
编写Dockerfile文件内容如下
FROM ubuntu:14.04 MAINTAINER nikefd <nikefd@gmail.com> RUN apt-get update RUN apt-get install -y build-essential python python-tornado strace python-pip RUN pip install tailer WORKDIR /opt/gr ADD . /opt/gr EXPOSE 8889 CMD ["python /opt/gr/server.py"]
需要在服务器上设置如下
sudo apt-get install apparmor-utils sudo aa-complain /etc/apparmor.d/docker sudo docker run --rm -t -i -p 8889:8889 ef6f0dc55814 /bin/bash
Step 2: communicate across link in two docker, one docker provide the gcc complier environment, the other call it
docker: relocation error: docker: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference
报这个错误的时候,运行
yum install device-mapper-event-libs
即可。 详见: http://stackoverflow.com/questions/27216473/docker-1-3-fails-to-start-on-rhel6-5 然后重启docker服务
碰到以下问题
91c95931e552: Error pulling image (latest) from hello-world, Driver devicemapper failed to create image rootfs a8219747be10611d65b7c693f48e7222c0bf54b5df8467d3f99003611afa1fd8: Error running DeviceCreate (createSnapDevice) dm_task_run failed reate (createSnapDevice) dm_task_run failed FATA[0022] Error pulling image (latest) from hello-world, Driver devicemapper failed to create image rootfs a8219747be10611d65b7c693f48e7222c0bf54b5df8467d3f99003611afa1fd8: Error running DeviceCreate (createSnapDevice) dm_task_run failed
解决方法: removing everything in /var/lib/docker
docker run -v /var/www/html/tjide/mysql:/var/lib/mysql -d --name mysql -e MYSQL_ROOT_PASSWORD=admin nikefd/mysql
docker run --rm -ti -v /var/www/html/tjide/userdata:/userdata -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):$(which docker) --link mysql:tomysql --name tjide0 -p 8000:8888 nikefd/tjide
参考链接: http://segmentfault.com/a/1190000000628247 https://docs.docker.com/userguide/ http://dockerpool.com/static/books/docker_practice/