一)docker基本命令:
1、docker search <镜像名称> 搜索镜像名称
2、docker pull <镜像名称> 下载镜像
3、docker images 查看镜像列表
4、docker rmi <镜像名称> 删除镜像
5、docker pull <镜像名称> 下载镜像
6、docker run ubuntu /bin/echo "hello world" 使用docker输出
7、docker ps -a 查看所有docker容器列表
8、docker ps -l 查看最后一个运行的容器
9、docker run [-d][--rm] --name mydocker -it ubuntu /bin/bash
运行镜像起容器,并且进入容器里(容器命名为mydocker)
-d后台启动.[--rm]退出后马上删除容器
10、docker inspect <容器id/容器名称> 查看容器信息
11、exit 退出容器
12、docker start [-i] <容器id/容器名称> 启动容器,-i进入容器
13、docker stop <容器id/容器名称> 停止容器
14、docker attach <容器id/容器名称> 进入容器(不一定成功)
15、nsenter 进入另外的容器,安装util-linux包
1)docker inspect --format '{{.State.Pid}}' <容器名称> 获取容器的pid
2)nsenter --target <容器的pid> --mount --uts --ipc --net --pid 进入容器
二)docker启动为容器:
1)端口映射:
docker run -d -P --name mynginx1 nginx -P端口的随机映射,-p 91:80端口的映射,非随机
2)数据卷:
docker run -it --name volume-test1 -h nginx -v /data ubuntu 设置数据卷
docker inspect -f {{.Volumes}} volume-test1
已经改为:sudo docker inspect volume-test1 | grep Source 查找映射宿主机的哪个目录
docker run -it --name volume-test2 -h nginx -v /opt:/opt:ro ubuntu:16.04
把宿主机上的/opt目录映射到容器的opt目录下,ro表示进去容器不能写,只读
docker run -it --name volume-test4 -h nginx --volumes-from volume-test1 ubuntu:16.04 数据卷容器
三)镜像构建:
1)手动构建:
手动构建中安装nginx所需的依赖:
apt-get install wget make
apt-get install openssl (openssl)
apt-get install libssl-dev (openssl)
apt-get install build-essential (gcc\g++)
添加用户
useradd -s /sbin/nologin -M wwww
./configure --prefix=/usr/local/nginx --user=wwww --group=wwww --with-http_ssl_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.41
配置nginx开机启动:
rc.local /usr/local/nginx/sbin/nginx
nginx.conf daemon off;
把容器提交成为镜像:
docker commit -m "message" 容器ID 镜像名称:标签名
2)Dockerfile自动构建
Dockerfie的demo如下(在ubuntu手动安装nginx):
# This is My first Dockerfile
# Base images
FROM ubuntu:16.04
MAINTAINER hyx
ADD nginx-1.10.3.tar.gz /usr/local/src
ADD pcre-8.41.tar.gz /usr/local/src
RUN apt-get update && apt-get install -y wget make openssl libssl-dev build-essential
RUN useradd -s /sbin/nologin -M www
WORKDIR /usr/local/src/nginx-1.10.3
RUN ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.41 && make && make install
RUN echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf
ENV PATH /usr/local/nginx/sbin:$PATH
EXPOSE 80
CMD ["nginx"]
构建镜像:
docker build -t nginx-file:v1 .
四)私人仓库
安装私人仓库:
docker pull registry
docker run -d --name myregistry -p 5001:5000 registry 把私有仓库起成容器
docker tag nginx-file:v1 192.168.10.63:5001/test/nginx-file:v1 标记tag
docker push 192.168.10.63:5001/test/nginx-file:v1 上传到私有仓库
--insecure-registry 192.168.10.63:5001 添加都配置文件/etc/default/docker下
五)docker其他:
安装压力测试工具:
apt-get install stress
下载repo
http://mirrors.aliyun.com/repo/
测试cpu的使用:
docker run -it --rm nginx-file:v1 --cpu 1
六)ubuntu下一些使用命令:
查看CPU参数
cat /proc/cpuinfo
brctl show 查看所有的网桥连接列表
iptables -t nat -L -n 查看网络连接nat表(查看虚拟机的所有服务的ip地址和端口映射关系)
ip ro li 查看路由表
ip ad li 查看地址表
netstat -ntlp 查看虚拟机的端口占用情况和程序名称
mv *.gz /usr/local/src 移动
tar zxf ***.gz 解压
apt-get update
apt install net-tools //ifconfig
apt install iputils-ping //ping
apt install iproute // ip
1、docker search <镜像名称> 搜索镜像名称
2、docker pull <镜像名称> 下载镜像
3、docker images 查看镜像列表
4、docker rmi <镜像名称> 删除镜像
5、docker pull <镜像名称> 下载镜像
6、docker run ubuntu /bin/echo "hello world" 使用docker输出
7、docker ps -a 查看所有docker容器列表
8、docker ps -l 查看最后一个运行的容器
9、docker run [-d][--rm] --name mydocker -it ubuntu /bin/bash
运行镜像起容器,并且进入容器里(容器命名为mydocker)
-d后台启动.[--rm]退出后马上删除容器
10、docker inspect <容器id/容器名称> 查看容器信息
11、exit 退出容器
12、docker start [-i] <容器id/容器名称> 启动容器,-i进入容器
13、docker stop <容器id/容器名称> 停止容器
14、docker attach <容器id/容器名称> 进入容器(不一定成功)
15、nsenter 进入另外的容器,安装util-linux包
1)docker inspect --format '{{.State.Pid}}' <容器名称> 获取容器的pid
2)nsenter --target <容器的pid> --mount --uts --ipc --net --pid 进入容器
二)docker启动为容器:
1)端口映射:
docker run -d -P --name mynginx1 nginx -P端口的随机映射,-p 91:80端口的映射,非随机
2)数据卷:
docker run -it --name volume-test1 -h nginx -v /data ubuntu 设置数据卷
docker inspect -f {{.Volumes}} volume-test1
已经改为:sudo docker inspect volume-test1 | grep Source 查找映射宿主机的哪个目录
docker run -it --name volume-test2 -h nginx -v /opt:/opt:ro ubuntu:16.04
把宿主机上的/opt目录映射到容器的opt目录下,ro表示进去容器不能写,只读
docker run -it --name volume-test4 -h nginx --volumes-from volume-test1 ubuntu:16.04 数据卷容器
三)镜像构建:
1)手动构建:
手动构建中安装nginx所需的依赖:
apt-get install wget make
apt-get install openssl (openssl)
apt-get install libssl-dev (openssl)
apt-get install build-essential (gcc\g++)
添加用户
useradd -s /sbin/nologin -M wwww
./configure --prefix=/usr/local/nginx --user=wwww --group=wwww --with-http_ssl_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.41
配置nginx开机启动:
rc.local /usr/local/nginx/sbin/nginx
nginx.conf daemon off;
把容器提交成为镜像:
docker commit -m "message" 容器ID 镜像名称:标签名
2)Dockerfile自动构建
Dockerfie的demo如下(在ubuntu手动安装nginx):
# This is My first Dockerfile
# Base images
FROM ubuntu:16.04
MAINTAINER hyx
ADD nginx-1.10.3.tar.gz /usr/local/src
ADD pcre-8.41.tar.gz /usr/local/src
RUN apt-get update && apt-get install -y wget make openssl libssl-dev build-essential
RUN useradd -s /sbin/nologin -M www
WORKDIR /usr/local/src/nginx-1.10.3
RUN ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.41 && make && make install
RUN echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf
ENV PATH /usr/local/nginx/sbin:$PATH
EXPOSE 80
CMD ["nginx"]
构建镜像:
docker build -t nginx-file:v1 .
四)私人仓库
安装私人仓库:
docker pull registry
docker run -d --name myregistry -p 5001:5000 registry 把私有仓库起成容器
docker tag nginx-file:v1 192.168.10.63:5001/test/nginx-file:v1 标记tag
docker push 192.168.10.63:5001/test/nginx-file:v1 上传到私有仓库
--insecure-registry 192.168.10.63:5001 添加都配置文件/etc/default/docker下
五)docker其他:
安装压力测试工具:
apt-get install stress
下载repo
http://mirrors.aliyun.com/repo/
测试cpu的使用:
docker run -it --rm nginx-file:v1 --cpu 1
六)ubuntu下一些使用命令:
查看CPU参数
cat /proc/cpuinfo
brctl show 查看所有的网桥连接列表
iptables -t nat -L -n 查看网络连接nat表(查看虚拟机的所有服务的ip地址和端口映射关系)
ip ro li 查看路由表
ip ad li 查看地址表
netstat -ntlp 查看虚拟机的端口占用情况和程序名称
mv *.gz /usr/local/src 移动
tar zxf ***.gz 解压
apt-get update
apt install net-tools //ifconfig
apt install iputils-ping //ping
apt install iproute // ip