Docker学习笔记02
?? 注:以下命令均来源自b站up主狂神说的Docker教学视频!
# --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
# docker run -c命令后接待完成的命令。
# -d, --detach Run container in background and print container ID
# -d参数意为在后台运行容器,并打印出该容器的ID。
# 死循环,输出信息,暂停1秒,继续输出信息。
docker run -d centos /bin/sh -c "while true;do echo caiwei;sleep 1;done"
# Fetch the logs of a container
# docker logs命令用来获取容器的日志。
# -f, --follow Follow log output
# --since string Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)
# -t, --timestamps Show timestamps
# --until string Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)
# -n, --tail string Number of lines to show from the end of the logs (default "all")
# -f意为跟踪日志输出。
# -t意为显示时间戳。
# --tail意为仅列出最新N条容器日志。
docker logs -tf --tail 0 CONTAINER ID
# 运行该命令一开始会直接显示最近的10条日志信息。
# Display the running processes of a container
# docker top命令查看容器中运行的进程信息。
docker top CONTAINER ID
# Linux top命令经常用来监控linux的系统状况,是常用的性能分析工具,能够实时显示系统中各个进程的资源占用情况。
top
# Run a command in a running container
# docker run命令用来在一个正在运行中的容器中执行一条命令。/新建容器,并启动该容器。
# -i, --interactive Keep STDIN open even if not attached
# --privileged Give extended privileges to the command
# -t, --tty Allocate a pseudo-TTY
# -it参数将会让docker分配一个伪终端来连接容器的标准输入,并在容器内创建一个交互性的bash命令行解释器。
# 进入当前正在运行的容器。
docker exec -it CONTAINER ID /bin/bash
# -e Select all processes. Identical to -A.
# -f Do full-format listing. This option can be combined with many other UNIX-style options to add additional columns. It
# also causes the command arguments to be printed. When used with -L, the NLWP (number of threads) and LWP (thread ID) columns # will be added. See the c option, the format keyword args, and the format keyword comm.
# ps-ef命令用于查看全格式的全部进程,其中“ps”是在Linux中是查看进程的命令,“-e”参数代表显示所有进程,“-f”参数代表全格式。
ps -ef
# Attach local standard input, output, and error streams to a running container
# docker attach :连接到正在运行中的容器。
docker attach CONTAINER ID
# 注:docker exec和docker attach命令的区别
# docker exec进入容器后开启一个新的终端,可以在里面操作(常用)。
# docker attach进入容器正在执行的终端,不会启动新的进程。
# Copy files/folders between a container and the local filesystem
# docker cp命令用于在容器和文件系统之间复制文件/文件夹。
# 将容器/home目录下的test.java文件复制到文件系统的/home目录下。
docker cp CONTAINER ID:/home/test/java /home
- 部署Nginx
# 在dockerhub上搜素Nginx镜像。
docker search nginx
# 从dockerhub上拉取一个镜像或一个仓库。
# 如果不指定版本号,则默认下载最新版本的镜像。
docker pull nginx
# 列出所有的镜像。【默认情况下,过滤掉中间镜像层】
docker images
# Run a command in a new container
# docker run命令用来在一个新的容器中运行一条命令。/新建容器,并启动该容器。
# -d, --detach Run container in background and print container ID
# --name string Assign a name to the container
# -p, --publish list Publish a container's port(s) to the host
# -d参数意为容器在后台运行;--name意为给容器命名;-p参数指定端口映射,格式为:主机(宿主)端口:容器端口
docker run -d --name nginx01 -p 8080:80 nginx
# List containers
# 列出所有的容器。
docker ps
# curl 是常用的命令行工具,用来请求 Web 服务器。
# 不带有任何参数时,curl 就是发出 GET 请求。
curl localhost:8080
效果图:
# whereis - locate the binary, source, and manual page files for a command
# Linux whereis命令用于查找文件。
whereis nginx
- 部署Tomcat
# Run a command in a new container
# docker run命令用来在一个新的容器中运行一条命令。/新建容器,并启动该容器。
# -i, --interactive Keep STDIN open even if not attached
# --privileged Give extended privileges to the command
# -t, --tty Allocate a pseudo-TTY
# -it参数将会让docker分配一个伪终端来连接容器的标准输入,并在容器内创建一个交互性的bash命令行解释器。
# --rm Automatically remove the container when it exits
# -rm参数,当容器存在的时候会自动移除容器。
# 我们之前的启动都是后台,停止了容器,容器还能查看到。docker run -it --rm,一般用来测试,用完就删除。
docker run -it --rm tomcat:9.0
# -d, --detach Run container in background and print container ID
# --name string Assign a name to the container
# -p, --publish list Publish a container's port(s) to the host
# -d参数意为容器在后台运行;--name意为给容器命名;-p参数指定端口映射,格式为:主机(宿主)端口:容器端口
docker run -d --name tomcat01 -p 8080:8080 tomcat
# Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
# -R, -r, --recursive copy directories recursively
# Linux cp(英文全拼:copy file)命令主要用于复制文件或目录。
# 将webapps.dist文件夹下的所有文件递归复制到webapps文件夹下。
cp -r webapps.dist/* webapps
效果图: