Docker的诱惑

it2023-03-29  76

文章目录

1、Docker简介1.1、Docker为什么会出现?1.2、Docker理念1.3、是什么? 2、Docker能干什么?2.1、容器虚拟化2.2、 一次构建、随处运行 3、Docker安装3.1、前提说明3.2、Docker的基本组成3.3、安装步骤3.4、永远的HelloWorld3.5、阿里云镜像加速3.6、底层原理3.7、为什么比VM快 4、Docker常用命令4.1、帮助命令4.2、镜像命令4.3、容器命令4.4、学习方法 5、容器数据卷5.1、是什么?5.2、能干什么?5.3、数据卷5.4、数据卷容器 6、DockerFile解析6.1、是什么?6.2、DockerFile构建过程 解析6.3、保留字指令 7、自定义镜像mycentos7.1、centos案例7.2、CMD/ENTRYPOINT7.3、ONBUILD7.4、自定义Tomcat7.5、在的定义的tomcat中发布web服务 8、Docker常用安装8.1、总体步骤8.2、安装tomcat8.3、安装mysql8.4、安装Redis 9、PUSH到阿里云仓库9.1、镜像生成的方法9.2、将本地镜像推送到阿里云

1、Docker简介

1.1、Docker为什么会出现?

避免开发和运维打架__

1.2、Docker理念

一次封装,到处运行

1.3、是什么?

解决了运行环境和配置问题,方便做持续集成并有助于整体发布的容器虚拟化技术

2、Docker能干什么?

2.1、容器虚拟化

2.2、 一次构建、随处运行

更快速的应用交付和部署更便捷的升级和扩缩容更简单的系统运维更高效的计算资源利用

3、Docker安装

3.1、前提说明

系统和内核版本的限制 去官网看一下 uname -r 3.10.0-1127.el7.x86_64 cat /etc/redhat-release CentOS Linux release 7.8.2003 (Core)

3.2、Docker的基本组成

镜像

       Docker镜像(image)就是一个只读的模板。镜像可以用来创建Docker容器,一个镜像可以创建很多容器。

Docker面向对象容器对象镜像类 容器

       Docker利用容器(Container)独立运行的一个或一组应用。容器是用镜像创建的运行实例        容器可以被启动、开始、停止、删除。每个容器都是互相隔离的、保证安全的平台        可以把容器看做一个简易版的Linux环境(包括root用户权限、进程空间、用户空间和网络空间)和运行在其中的应用程序。        容器的定义和镜像几乎一模一样,也就是一堆层的统一视角,唯一的区别在于容器的最上边的那一层是可读可写的

仓库(Repository)

       仓库是集中存放镜像文件的场所        仓库和仓库注册服务器(Registry)是有区别的。仓库注册服务器上往往存放着许多仓库,每个仓库中又包含多个镜像,每个镜像有不同的标签(tag)。

总结

3.3、安装步骤

1.必须能上网 2. yum -y install gcc gcc -v gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 3. yum -y install gcc-c++ g++ -v gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ----------------- 卸载旧版本 yum -y remove docker docker-common docker-selinux docker-engine ----------------- 4.安装需要的软件包 yum install -y yum-utils device-mapper-persistent-data lvm2 5.设置库 yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo ------------------------------ Loaded plugins: fastestmirror adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo -------------------------------- 6. 更新yum软件包检索 yum makecache fast 7.安装DOCKER CE yum -y install docker-ce --nogpgcheck ------------------------------- Installed: docker-ce.x86_64 3:19.03.13-3.el7 ------------------------------- 8.启动docker systemctl start docker 9. 查看版本 docker version ---------- Client: Docker Engine - Community Version: 19.03.13 API version: 1.40 Go version: go1.13.15 Git commit: 4484c46d9d Built: Wed Sep 16 17:03:45 2020 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03.13 API version: 1.40 (minimum version 1.12) Go version: go1.13.15 Git commit: 4484c46d9d Built: Wed Sep 16 17:02:21 2020 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.3.7 GitCommit: 8fba4e9a7d01810a393d5d25a3621dc101981175 runc: Version: 1.0.0-rc10 GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd docker-init: Version: 0.18.0 GitCommit: fec3683 ---------- 11.卸载 systemctl stop docker yum -y remove docker-ce rm -rf /var/lib/docker

3.4、永远的HelloWorld

10. 测试 docker run hello-world(镜像名) ------------------------------------------------------ Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 0e03bdcc26d7: Pull complete Digest: sha256:8c5aeeb6a5f3ba4883347d3747a7249f491766ca1caa47e5da5dfcf6b9b717c0 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/

3.5、阿里云镜像加速

https://cr.console.aliyun.com/cn-qingdao/instances/mirrors sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://o66gqcsszc.mirror.aliyuncs.com"] (//后面的写自己的,这个是错的) } EOF sudo systemctl daemon-reload sudo systemctl restart docker

3.6、底层原理

3.7、为什么比VM快

4、Docker常用命令

4.1、帮助命令

docker version docker info docker help

4.2、镜像命令

docker images -a 列出本地所有的镜像(含 中间映像层) -q 只显示镜像ID --digests 显示镜像的摘要信息 --no-trunc 显示完整镜像信息 docker search 某个xxx镜像的名称 (在官网查) -s 列出不少于指定数量的点赞数的镜像 --automated 只列出automated build类型的镜像 自动构建 docker pull 某个xxx镜像名称名称 docker pull 镜像名称[:TAG] docker rmi 某个xxx镜像名字ID docker rmi [OPTIONS] IMAGE [IMAGE...] docker rmi -f ${docker images -qa} docker ps 列出当前所有正在运行的容器

4.3、容器命令

1 启动容器 docker run [OPTIONS] IMAGE [COMMAND] [ARG...] OPTIONS: --name="容器新名字":为容器指定一个名称 -d 后台运行容器 并返回容器ID 即启动守护式容器 -i 以交互式模式运行容器通常与-t同时使用 -t 为容器重新分配一个伪输入终端,通常与-i同时使用 -P 随机端口映射 -p 指定端口映射 ip:hostPort:containerPort ip::containerPort hostPost:containerPort containerPort 2 退出容器(在容器虚拟终端内部) - exit 容器同时也停止 - ctrl + p + q

4.4、学习方法

docekr --help ---------------------------------------------------------- Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/root/.docker") -c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") --tlskey string Path to TLS key file (default "/root/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: builder Manage builds config Manage Docker configs container Manage containers context Manage contexts engine Manage the docker engine image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker trust Manage trust on Docker images volume Manage volumes Commands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes Run 'docker COMMAND --help' for more information on a command. [root@node4 ~]# docker run --help Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] Run a command in a new container Options: --add-host list Add a custom host-to-IP mapping (host:ip) -a, --attach list Attach to STDIN, STDOUT or STDERR --blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0) --blkio-weight-device list Block IO weight (relative device weight) (default []) --cap-add list Add Linux capabilities --cap-drop list Drop Linux capabilities --cgroup-parent string Optional parent cgroup for the container --cidfile string Write the container ID to the file --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota --cpu-rt-period int Limit CPU real-time period in microseconds --cpu-rt-runtime int Limit CPU real-time runtime in microseconds -c, --cpu-shares int CPU shares (relative weight) --cpus decimal Number of CPUs --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1) --cpuset-mems string MEMs in which to allow execution (0-3, 0,1) -d, --detach Run container in background and print container ID --detach-keys string Override the key sequence for detaching a container --device list Add a host device to the container --device-cgroup-rule list Add a rule to the cgroup allowed devices list --device-read-bps list Limit read rate (bytes per second) from a device (default []) --device-read-iops list Limit read rate (IO per second) from a device (default []) --device-write-bps list Limit write rate (bytes per second) to a device (default []) --device-write-iops list Limit write rate (IO per second) to a device (default []) --disable-content-trust Skip image verification (default true) --dns list Set custom DNS servers --dns-option list Set DNS options --dns-search list Set custom DNS search domains --domainname string Container NIS domain name --entrypoint string Overwrite the default ENTRYPOINT of the image -e, --env list Set environment variables --env-file list Read in a file of environment variables --expose list Expose a port or a range of ports --gpus gpu-request GPU devices to add to the container ('all' to pass all GPUs) --group-add list Add additional groups to join --health-cmd string Command to run to check health --health-interval duration Time between running the check (ms|s|m|h) (default 0s) --health-retries int Consecutive failures needed to report unhealthy --health-start-period duration Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s) --health-timeout duration Maximum time to allow one check to run (ms|s|m|h) (default 0s) --help Print usage -h, --hostname string Container host name --init Run an init inside the container that forwards signals and reaps processes -i, --interactive Keep STDIN open even if not attached --ip string IPv4 address (e.g., 172.30.100.104) --ip6 string IPv6 address (e.g., 2001:db8::33) --ipc string IPC mode to use --isolation string Container isolation technology --kernel-memory bytes Kernel memory limit -l, --label list Set meta data on a container --label-file list Read in a line delimited file of labels --link list Add link to another container --link-local-ip list Container IPv4/IPv6 link-local addresses --log-driver string Logging driver for the container --log-opt list Log driver options --mac-address string Container MAC address (e.g., 92:d0:c6:0a:29:33) -m, --memory bytes Memory limit --memory-reservation bytes Memory soft limit --memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap --memory-swappiness int Tune container memory swappiness (0 to 100) (default -1) --mount mount Attach a filesystem mount to the container --name string Assign a name to the container --network network Connect a container to a network --network-alias list Add network-scoped alias for the container --no-healthcheck Disable any container-specified HEALTHCHECK --oom-kill-disable Disable OOM Killer --oom-score-adj int Tune host's OOM preferences (-1000 to 1000) --pid string PID namespace to use --pids-limit int Tune container pids limit (set -1 for unlimited) --platform string Set platform if server is multi-platform capable --privileged Give extended privileges to this container -p, --publish list Publish a container's port(s) to the host -P, --publish-all Publish all exposed ports to random ports --read-only Mount the container's root filesystem as read only --restart string Restart policy to apply when a container exits (default "no") --rm Automatically remove the container when it exits --runtime string Runtime to use for this container --security-opt list Security Options --shm-size bytes Size of /dev/shm --sig-proxy Proxy received signals to the process (default true) --stop-signal string Signal to stop a container (default "SIGTERM") --stop-timeout int Timeout (in seconds) to stop a container --storage-opt list Storage driver options for the container --sysctl map Sysctl options (default map[]) --tmpfs list Mount a tmpfs directory -t, --tty Allocate a pseudo-TTY --ulimit ulimit Ulimit options (default []) -u, --user string Username or UID (format: <name|uid>[:<group|gid>]) --userns string User namespace to use --uts string UTS namespace to use -v, --volume list Bind mount a volume --volume-driver string Optional volume driver for the container --volumes-from list Mount volumes from the specified container(s) -w, --workdir string Working directory inside the container [root@node4 ~]# docker container Usage: docker container COMMAND Manage containers Commands: attach Attach local standard input, output, and error streams to a running container commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem exec Run a command in a running container export Export a container's filesystem as a tar archive inspect Display detailed information on one or more containers kill Kill one or more running containers logs Fetch the logs of a container ls List containers pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container prune Remove all stopped containers rename Rename a container restart Restart one or more containers rm Remove one or more containers run Run a command in a new container start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers wait Block until one or more containers stop, then print their exit codes Run 'docker container COMMAND --help' for more information on a command. [root@node4 ~]# docker image Usage: docker image COMMAND Manage images Commands: build Build an image from a Dockerfile history Show the history of an image import Import the contents from a tarball to create a filesystem image inspect Display detailed information on one or more images load Load an image from a tar archive or STDIN ls List images prune Remove unused images pull Pull an image or a repository from a registry push Push an image or a repository to a registry rm Remove one or more images save Save one or more images to a tar archive (streamed to STDOUT by default) tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE Run 'docker image COMMAND --help' for more information on a command.

5、容器数据卷

5.1、是什么?

有点类似我们Redis里面的rdb和aof文件

5.2、能干什么?

容器的持久化 容器间的继承+共享数据 <!-- --> 卷就是目录或文件,存在于一个或多个容器中,由docker挂载到容器,但不属于联合文件系统,因此能绕过UnionFS 提供一些用于持续存储或共享数据的特性 卷的设计目的就是数据的持久化,完全独立于容器的生存周期,因此Docker不会在容器删除时删除其挂载的数据卷 <!-- 特点 --> 1 数据卷可在容器之间共享或重用数据 2 卷中的更改可以直接生效 3 数据卷中的更改不会包含在镜像的更新中 4 数据卷的生命周期一直持续到没有容器使用它为止

5.3、数据卷

## 容器内添加 #1 直接命令添加 docker run -it -v /宿主机绝对路径:/容器内目录 镜像名 docker run -it -v /myDataVolume:/dataVolumeContainer centos docker run -it -v /宿主机绝对路径:/容器内目录:ro 镜像名 ## 只支持主机单向修改,容器只能读 #2 DockerFile添加 通过镜像描述文件来创建自己的镜像,当然就可以在创建的时候,先指定镜像共享文件路径

5.4、数据卷容器

## 数据的继承和共享 ## 数据的持久化 -------------------------------- ########################创建DockerFile################### FROM centos VOLUME ["/dataVolumeContainer1","/dataVolumeContainer2"] ## docker会自动在宿主机上新建数据卷的持久化目录 通过 docker inspect 容器名 来查看路径 CMD echo "finshed,--------success1" CMD /bin/bash -------------------------------- # 通过DockerFile来创建镜像 -------------------------------- docker build -f /mydocker/DockerFile -t **/centos -------------------------------- #通过DockerFile创建镜像启动容器 docker run -it --name dc01 **/centos dc02&&dc03 继承dc01 docker run -it --name dc02 --volumes-from dc01 **/centos docker run -it --name dc03 --volumes-from dc01 **/centos 在dc01的数据卷创建文件,把dc01退出,dc02\dc03上都会有,如果再把dc02退出,dc03上也有 ###############数据卷的生命周期 直到没有容器去使用######################

6、DockerFile解析

6.1、是什么?

DockerFile 是用来构建Docker镜像的构建文件,是由一系列命令和参数构建的脚本 通过配置文件描述镜像,可以构建自己的镜像

6.2、DockerFile构建过程 解析

基础知识 每条保留字指令都必须为大写字母且后面跟随至少一个参数 指令按照从上到下,顺序执行 #表示注释 每条指令都会创建一个新的镜像层,并对镜像进行提交 Docker执行DockerFile的大致步骤 docker从基础镜像运行一个容器 执行一条指令并对容器做出修改 执行类似 docker commit的操作提交一个新的镜像层 docker再基于刚提交的镜像运行一个新容器 执行dockerfile中的下一条指令直到所有指令执行完成 总结 DockerFile是软件的原材料 Docker镜像是软件的交付品 Docker容器可以认为是软件的运行态 DockerFile面向开发,Docker镜像成为交付标准,Docker容器则涉及部署与运维,三者缺一不可,合力充当Docker体系的基石

6.3、保留字指令

ADD 后面的URL和压缩包,docker会自动解析、解压 COPY 如果后面直接跟压缩包会出问题,不会自动解压 CMD 后面指定的命令,最终只有最后一个命令会执行 ENTRYPOINT 后面的命令属于追加 ONBUILD 一旦镜像被继承,则触发后面指令 EXPOSE 对外暴露接口 ENV 在构建镜像过程中,设置环境变量 WORKDIR 一登录所在的目录

7、自定义镜像mycentos

7.1、centos案例

编写DockerFile配置 ## /mydocker/DockerFile2 FROM centos MAINTAINER **<**@gmail.com> ENV MYPATH /usr/local WORKDIR $MYPATH RUN yum -y install vim RUN yum -y install net-tools EXPOSE 80 CMD echo $MYPATH CMD echo "success------------ok" CMD /bin/bash build配置文件 docker build -f /mydocker/DockerFile2 -t mycentos:1.3 . 运行images docker run -it mycentos:1.3

7.2、CMD/ENTRYPOINT

docekr run -it -p 7777:8080 ### CMD 在Dockerfile最后 CMD 后面跟着命令 如果run 一个镜像实例,在后面添加参数时,会报错,因为会把CMD后加的 命令覆盖,而run的时候加的参数根本不是命令,所以会报错 ### ENTRYPOINT 在Dockerfile最后 ENTRYPOINT 后面跟着命令 如果run 一个镜像实例,在后面添加参数时,docker会默认将参数 追加到 ENTRYPOINT 后面跟着的命令后,作为一个参数,这样命令就更强大了

7.3、ONBUILD

FROM centos RUN yum install -y curl ENTRYPOINT ["curl","-s","http://ip.cn"] ONBUILD RUN echo "father onbuild------------886" ## 如果有其他镜像要基于上面镜像进行构建,在build时,会触发ONBUILD后面的命令

7.4、自定义Tomcat

创建Dockerfile # /mydocker/tomcat vim Dockerfile FROM centos MAINTAINER h**<***@gmail.com> #把宿主机当前上下文的c.txt拷贝到容器 /usr/local路径下 COPY c.txt /usr/local/cincontainer.txt ADD jdk-8u202-linux-x64.tar.gz /usr/local/ ADD apache-tomcat-8.5.58.tar.gz /usr/local/ # 安装vim编辑器 RUN yum -y install vim #设置工作访问时候的WORKDIR路径,登录落脚点 ENV MYPATH /usr/local WORKDIR $MYPATH #配置java与tomcat环境变量 ENV JAVA_HOME /usr/local/jdk1.8.0_202 ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.58 ENV CATALINA_BASE /usr/local/apache-tomcat-8.5.58 ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin #容器运行时监听的端口 EXPOSE 8080 #启动时运行tomcat #ENTRYPOINT ["/usr/local/apache-tomcat-8.5.58/bin/startup.sh"] #CMD["/usr/local/apache-tomcat-8.5.58/bin/catalina.sh","run"] CMD /usr/local/apache-tomcat-8.5.58/bin/startup.sh && tail -F /usr/local/apache-tomcat-8.5.58/bin/logs/catalina.out 构建 ## /mydocker/tomcat docker build -t *tomcat8 . 运行 docker run -d -p 9080:8080 --name myt8 -v /mydocker/tomcat/test:/usr/local/apache-tomcat-8.5.58/webapps/test -v /mydocker/tomcat/tomcatlogs/:/usr/local/apache-tomcat-8.5.58/logs --privileged=true **tomcat8:latest

运行下面的命令

docker run -d -p 9080:8080 --name myt8 -v /mydocker/tomcat/test:/usr/local/apache-tomcat-8.5.58/webapps/test -v /mydocker/tomcat/tomcatlogs/:/usr/local/apache-tomcat-8.5.58/logs --privileged=true **tomcat8:latest

7.5、在的定义的tomcat中发布web服务

## /mydocker/tomcat/test mkdir WEB-INF cd WEB-INF vim web.xml ------------ ------------ cd .. vim index.jsp ----------- ----------- <!-- web.xml --> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> </web-app> <!-- index.jsp --> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" %> <html> <head> <title>Title</title> </head> <body> <div style="width:270px;height: 30px"><font color="red">${errMsg}</font></div> <%="i am in docker tomcat self"%> <form action="transfer.action" method="post"> dst:<input type="text" name="outName"><br/> goal:<input type="text" name="inName"><br/> money:<input type="text" name="money"><br/> <input type="submit" value="ok"/> </form> <%System.out.printlin("=============docaker tomcat self");%> </body> </html> docker exec 2ebfdba94b30 ls -l /usr/local/apache-tomcat-8.5.58/webapps/test drwxr-xr-x. 2 root root 21 Oct 19 15:15 WEB-INF -rw-r--r--. 1 root root 623 Oct 19 15:15 index.jsp ##重启容器 docker restart 容器名

8、Docker常用安装

8.1、总体步骤

8.2、安装tomcat

8.3、安装mysql

搜索镜像 docker search mysql 拉取镜像 docker pull mysql:5.6 运行镜像 docker run -p 12345:3306 --name mysql -v /mydocker/mysql/conf:/etc/mysql/conf.d -v /mydocker/mysql/logs:/logs -v /mydocker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6 docker run -p 12345:3306 --name mysql -v /mydocker/mysql/conf:/etc/mysql/conf.d -v /mydocker/mysql/logs:/logs -v /mydocker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6 外部win10连接运行在docker上的mysql服务数据备份 docker exec 容器ID sh -c ' exec mysqldump --all-databases -uroot -p"123456" ' > /mydocker/mysql/all.sql

8.4、安装Redis

拉取镜像 docker pull redis:3.2 启动redis docker run -p 6379:6379 -v /mydocker/myredis/data:/data -v /mydocker/myredis/conf/redis.conf:/usr/local/etc/redis/redis.conf -d redis:3.2 redis-server /usr/local/etc/redis/redis.conf --appendonly yes docker run -p 6379:6379 -v /mydocker/myredis/data:/data -v /mydocker/myredis/conf/redis.conf:/usr/local/etc/redis/redis.conf -d redis:3.2 redis-server /usr/local/etc/redis/redis.conf --appendonly yes 创建配置文件 vim /mydocker/myredis/conf/redis.conf/redis.conf

9、PUSH到阿里云仓库

9.1、镜像生成的方法

通过DockerFile生成从容器创建一个新的镜像 docker commit -a "yhw" -m "new mycentos with vim and ifconfig" 正在运行的容器id 新的镜像名:tag

9.2、将本地镜像推送到阿里云

$ sudo docker login --username=**********@qq.com registry.cn-shanghai.aliyuncs.com $ sudo docker tag [ImageId] registry.cn-shanghai.aliyuncs.com/***/mycentos:[镜像版本号] $ sudo docker push registry.cn-shanghai.aliyuncs.com/**/mycentos:[镜像版本号] docker login --username=*******@qq.com registry.cn-shanghai.aliyuncs.com docker tag 1e4bf6b2ed06 registry.cn-shanghai.aliyuncs.com/***/mycentos:1.0 docker push registry.cn-shanghai.aliyuncs.com/***/mycentos:[镜像版本号]
最新回复(0)