docker 二进制安装
tar -xvf docker-18.06.3-ce.tgz
#这一步我没做,我直接在 /usr/lcoal下解压的docke压缩文件
cp docker/* /usr/local/bin
#创建docker.service文件
vi /etc/systemd/system/docker.service
docker.service文件中输入内容并保存
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
#docker.service 设置为可执行文件
chmod +x /usr/lib/systemd/system/docker.service
#重载systemd下 xxx.service文件
systemctl daemon-reload
#启动Docker
systemctl start docker
#设置开机自启
systemctl enable docker.service
#查看Docker状态
systemctl status docker
#查看Docker版本
docker -v
docker常用命令
#查看当前正在运行的容器
docker ps
#查看所有容器的状态
docker ps -a
#启动/停止某个容器
docker start/stop id/name
#停止守护式容器
docker kill id/name
#进入某个容器(使用exit退出后容器也跟着停止运行)
docker attach id
#启动一个伪终端以交互式的方式进入某个容器(使用exit退出后容器不停止运行)
docker exec -ti id
#查看本地镜像
docker images
#删除某个容器
docker rm id/name
#删除某个镜像
docker rmi id/name
#复制ubuntu容器并且重命名为test且运行,然后以伪终端交互式方式进入容器,运行bash
docker run --name test -i -t ubuntu /bin/bash
#通过当前目录下的Dockerfile创建一个名为soar/centos:7.1的镜像,最后变有一个 . 一定不要忘记
docker build -t soar/centos:7.1 .
#以镜像soar/centos:7.1创建名为test的容器,并以后台模式运行,并做端口映射到宿主机2222端口,P参数重启容器宿主机端口会发生改变
docker run -d -p 2222:22 --name test soar/centos:7.1
#镜像后台模式运行时,查看镜像运行的日志情况,-f 一直跟踪日志的变化并返回结果,-t 增加时间戳 -tail 显示最新的多少条日志
docker logs -tf -tail 10 test
#Search images
sudo docker search ubuntu
#获取镜像的信息
docker inspect id/name
修改docker镜像源
docker默认镜像源
vi /etc/docker/daemon.json
#增加 daemon.json 文件并修改镜像源
cat >/etc/docker/daemon.json <<-EOF
{
"registry-mirrors": ["https://registry.docker-cn.com","http://hub-mirror.c.163.com"]
}
EOF
#重启生效
systemctl restart docker.service
docker安装nginx
#查看所有镜像
docker images
#docker拉取nginx镜像
docker pull nginx
dockerfile 指令
#FROM ubuntu:14.04
FROM <image>
#指定镜像的作者信息
MAINTAINER <name>
#shell 模式 RUN /bin/sh -c command
RUN <command>
#exec 模式 RUN["/bin/bash","-c","echo hello"]
RUN ["executable","param1","param2"]
#指定运行该镜像的容器使用的端口
EXPOSE <port>
#镜像run运行过程中执行的命令,会被docker run -d images command 中的命令覆盖
CMD <command>
#不会被docker run -d images command 中的命令覆盖
ENTRYPOINT command param1 param2
#ADD包含类似tar的解压功能
ADD src dest
#如果单纯复制文件,docker推荐使用copy
#当前目录下的index.html复制到/usr/share/nginx/html/目录下
COPY index.html /usr/share/nginx/html/