docker用法与实例
2018-11-26 08:58
956 查看
- 镜像:
a. 拉取:docker pull 名称
b. 查看:
docker image ls -a
c. 删除指定镜像:
docker image rm -f 名称
d. 删除无用镜像:
docker image prune
- 容器:
a. 初始化:docker run -p 本地端口:镜像内端口 -v 本地文件:远程文件 -d(后台运行) -it(交互式运行) 镜像名
b. 启动:
docker container start 短名称
c. 停止:
docker container stop 短名称
d. 删除指定容器:
docker container rm -f 名称
e. 删除停止中的容器:
docker container prune
- 实例(使用官方centos镜像搭建nginx):
a. 创建文件夹:mkdir -p nginx/{conf,www}
b. 创建nginx配置文件:
vim nginx/conf/nginx.confdaemon off; user nginx; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
c. 创建测试文件:
vim nginx/www/index.htmlhello
d. 创建Dockerfile文件:
vim DockerfileFROM centos RUN yum -y install pcre-devel \ && yum -y install zlib-devel \ && yum -y install wget \ && yum -y install gcc automake autoconf libtool make \ && mkdir /data \ && cd /data \ && wget https://nginx.org/download/nginx-1.15.6.tar.gz \ && tar -xzf nginx-1.15.6.tar.gz \ && cd nginx-1.15.6 \ && ./configure \ && make \ && make install \ && useradd -s /sbin/nologin -M nginx COPY $PWD/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf COPY $PWD/nginx/www/index.html /usr/local/nginx/html/index.html CMD ["/usr/local/nginx/sbin/nginx"]
e. 创建镜像:
docker build -t test .
f. 运行:docker run -p 80:80 -d test
g. 测试:curl localhost
- 参考文档:
a. 源码安装nginx:
https://www.geek-share.com/detail/2747887004.html
b. docker中文教程:
https://yeasy.gitbooks.io/docker_practice/content/
相关文章推荐
- docker用法与实例
- Python类的用法实例浅析
- perl 二维数组的用法实例
- sql事务(Transaction)用法介绍及回滚实例
- Android开发之Sqliteopenhelper用法实例分析
- Oracle Merge Into 的用法详解实例
- oracle跨库查询dblink的用法实例详解
- pthread_join/pthread_exit用法实例
- Flex Meta标记 的用法实例
- CodeIgniter钩子用法实例详解
- JQuery中DOM事件合成用法实例分析
- 实例讲解sed的9种常见用法
- java中List的用法和实例详解
- PHP中curl_setopt函数用法实例分析
- 关于Button控件的CommandName属性用法的一个实例
- python中元类用法实例
- python关键字and和or用法实例
- linux shell中利用awk获取关键字符的用法,实例说明。
- jQuery中parentsUntil()方法用法实例
- UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法 (实例)