file-type

Docker配置实践:构建与执行指令详解

ZIP文件

下载需积分: 9 | 3KB | 更新于2025-09-03 | 198 浏览量 | 0 下载量 举报 收藏
download 立即下载
### Docker配置 Docker作为一个开源的应用容器引擎,允许开发者打包他们的应用以及应用的依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app)。 #### Docker基本命令解析 在提供的描述中提到了一系列的docker相关命令,下面对这些命令进行逐一解析: 1. `docker-compose build app`:该命令是用来构建或重新构建服务中的应用容器。构建过程会依照`docker-compose.yml`文件中的配置,如果构建过程中出现变动,容器会被重新构建。 2. `docker-compose up -d`:该命令用于启动并运行一个或多个服务。参数`-d`表示后台运行容器,并打印容器的名称。 3. `docker-compose ps`:此命令用于查看由`docker-compose`启动的服务的状态。会显示容器的服务名称、状态、端口等信息。 4. `docker-compose exec app ls -l`:此命令用于在服务`app`的容器内执行`ls -l`命令,列出容器内当前目录下的详细信息。 5. `docker-compose exec app composer install`:在服务`app`的容器内执行`composer install`命令,用于安装或更新依赖包,这对于PHP项目尤为重要。 6. `docker-compose exec app php artisan key:generate`:在服务`app`的容器内执行PHP的`artisan`命令来生成应用的安全密钥,对于Laravel框架是初始化项目配置的一部分。 #### Dockerfile Dockerfile是一个文本格式的配置文件,用户可以使用Dockerfile来创建自动构建的Docker镜像。Dockerfile中包含了使用特定指令创建镜像的步骤。这些指令是面向开发者的,允许他们快速的在Docker中自动化构建过程。 Dockerfile通常包含以下指令: - FROM:指定基础镜像,所有Dockerfile都必须以FROM开始。 - RUN:运行命令,表示在构建过程中运行指定的命令。 - CMD:容器启动命令,指定容器启动时默认执行的命令。 - COPY:复制指令,从宿主机复制文件或者目录到容器中。 - ADD:高级复制指令,与COPY相似,但ADD拥有自动解压缩的功能并且可以使用URL。 - ENV:设置环境变量。 - EXPOSE:声明容器运行的端口。 - VOLUME:创建挂载点目录,用于保持容器持久化或共享数据。 - WORKDIR:设置工作目录。 #### 关于压缩包子文件的文件名称列表 "docker-configuration-master"这个名字暗示了我们所讨论的文件、脚本或资源可能是Docker配置的一部分,并且有可能包含了多个服务的配置。在项目中,这种文件通常会包含Dockerfile、docker-compose.yml以及可能涉及的配置脚本、环境变量文件等。这些资源通常会被放置在版本控制系统中,方便团队协作和版本迭代。"master"表示这些配置可能属于主分支,或者是主配置文件。 总结来说,通过理解和应用这些Docker配置相关的命令和Dockerfile,开发者可以高效地构建、部署和管理他们的应用。而熟练掌握这些知识点,对于IT行业的专业人员来说,是进行现代云服务和容器化应用开发的基础技能。

相关推荐

filetype

root@iZ2ze3qhya9blvlx5gep84Z:/home/nginx-power# docker logs --tail 20 4daa /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates. sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes. sh /docker-entrypoint.sh: Configuration complete; ready for start up nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directi ve in /etc/nginx/conf.d/default.conf:2 /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perf orm configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-defa ult.sh 10-listen-on-ipv6-by-default.sh: info: can not modify /etc/nginx/conf.d/default .conf (read-only file system?) /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates. sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes. sh /docker-entrypoint.sh: Configuration complete; ready for start up nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directi ve in /etc/nginx/conf.d/default.conf:2 /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perf orm configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-defa ult.sh 10-listen-on-ipv6-by-default.sh: info: can not modify /etc/nginx/conf.d/default .conf (read-only file system?) /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates. sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes. sh /docker-entrypoint.sh: Configuration complete; ready for start up nginx: [warn] conflicting server name "localhost" on 0.0.0.0:9007, ignored

filetype

已知这是后端项目中的application.yml中的部分内容: server: port: 9090 spring: data: redis: port: 6379 host: cache-server1 password: 123456 datasource: url: jdbc:mysql://db-server1:3306/docker?useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8&useUnicode=true username: root password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver mybatis: mapper-locations: classpath*:mapper/*.xml type-aliases-package: com.lu.hotel.entity configuration: map-underscore-to-camel-case: true 把后端项目打包成hotel-0.0.1-SNAPSHOT.jar后,在docker中使用docker compose对springboot项目进行部署,新建了一个mydata目录,下面是dockerfile,docker-compose.yml,mysql,redis和hotel-0.0.1-SNAPSHOT.jar,其中把数据库的hotel.sql文件放在了mysql/init下面,hotel.sql是整个数据库的SQL文件,里面有很多表,已知dockerfile的内容如下: FROM openjdk:23-jdk-bookworm MAINTAINER docker COPY hotel-0.0.1-SNAPSHOT.jar /hotel.jar ENTRYPOINT ["java", "-jar", "/hotel.jar"] EXPOSE 9090 已知docker-compose.yml的文件内容如下: services: back-server: build: . container_name: hotel ports: - "9090:9090" networks: - demo_net depends_on: - cache-server - db-server cache-server: image: redis:6.0.8 container_name: "cache-server1" ports: - "6379:6379" volumes: - ./redis/data:/data networks: demo_net: ipv4_address: 172.16.0.4 db-server: image: mysql:5.7 container_name: "db-server1" environment: MYSQL_ROOT_PASSWORD: 'root' MYSQL_ALLOW_EMPTY_PASSWORD: 'no' MYSQL_DATABASE: 'docker' MYSQL_USER: 'docker' MYSQL_PASSWORD: 'docker' ports: - "3307:3306" volumes: - ./mysql/db:/var/lib/mysql - ./mysql/init:/docker-entrypoint-initdb.d networks: demo_net: ipv4_address: 172.16.0.3 command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci networks: demo_net: ipam: config: - subnet: 172.16.0.0/24 以上部分

filetype

apiVersion: v1 kind: Pod spec: containers: - args: ['$(JENKINS_SECRET)', '$(JENKINS_NAME)'] image: "registry.cn-beijing.aliyuncs.com/citools/jnlp:alpine" name: jnlp imagePullPolicy: IfNotPresent volumeMounts: - mountPath: "/etc/localtime" name: "localtime" readOnly: false - command: - "cat" env: - name: "LANGUAGE" value: "en_US:en" - name: "LC_ALL" value: "en_US.UTF-8" - name: "LANG" value: "en_US.UTF-8" image: "registry.cn-beijing.aliyuncs.com/citools/maven:3.5.3" imagePullPolicy: "IfNotPresent" name: "build" volumeMounts: - mountPath: "/etc/localtime" name: "localtime" - mountPath: "/root/.m2/" name: "cachedir" readOnly: false - command: - "cat" env: - name: "LANGUAGE" value: "en_US:en" - name: "LC_ALL" value: "en_US.UTF-8" - name: "LANG" value: "en_US.UTF-8" image: "registry.cn-beijing.aliyuncs.com/citools/kubectl:self-1.17" imagePullPolicy: "IfNotPresent" name: "kubectl" tty: true volumeMounts: - mountPath: "/etc/localtime" name: "localtime" readOnly: false - command: - "cat" env: - name: "LANGUAGE" value: "en_US:en" - name: "LC_ALL" value: "en_US.UTF-8" - name: "LANG" value: "en_US.UTF-8" image: "registry.cn-beijing.aliyuncs.com/citools/docker:19.03.9-git" imagePullPolicy: "IfNotPresent" name: "docker" tty: true volumeMounts: - mountPath: "/etc/localtime" name: "localtime" readOnly: false - mountPath: "/var/run/docker.sock" name: "dockersock" readOnly: false restartPolicy: "Never" nodeSelector: build: "true" volumes: - hostPath: path: "/var/run/docker.sock" name: "dockersock" - hostPath: path: "/usr/share/zoneinfo/Asia/Shanghai" name: "localtime" - name: "cachedir" hostPath: path: "/opt/m2" 用这个文件怎么在jenkins中生成k8s做agent的模板