docker compose linux tomcat 安装(多容器docker)

本文介绍如何使用Docker和Docker Compose来部署Tomcat应用服务器及Sonatype Nexus仓库管理器。首先通过YUM安装Docker并启动服务,接着安装Python的pip工具以下载Docker Compose。配置完成后,编写Docker Compose YAML文件定义Tomcat和Nexus的服务,映射宿主机目录以持久化数据,并暴露所需端口。最后运行Docker Compose启动容器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

docker compose linux  tomcat 安装

 

0.docker 安装

yum install docker-io 
service docker start

 

 

1.安装pip

yum -y install epel-release
yum -y install python-pip

 

2.下载docker compose

pip install docker-compose

 

3.docker version

docker-compose version



  

 

4.编写 yaml 语法

version: "2"
services:
        web1:
                image: tomcat
                ports:
                     - 8080
                volumes:
                       - /docker/tomcat1/server:/usr/local/tomcat/webapps/
                       - /docker/tomcat1/logs:/usr/local/tomcat/logs
        web2:
                image: sonatype/nexus
                ports:
                     - "8081:8081"
                volumes:
                        - /docker/nexus/data:/sonatype-work

 

 

5.运行

docker-compose up 

 

6.启动日志



 

7.后台进程



 

8.docker down 



 

 

 

 9. docker compose 常见命令

[root@bogon tomcat-maven]# docker compose --help

Usage:	docker COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/root/.docker")
  -D, --debug              Enable debug mode
      --help               Print usage
  -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:
  config      Manage Docker configs
  container   Manage containers
  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
  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.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者 

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。

 

个人主页http://knight-black-bob.iteye.com/



 
 
 谢谢您的赞助,我会做的更好!

### 使用 Docker Compose 安装配置 Tomcat 和 MySQL #### 创建 `docker-compose.yml` 文件 为了使用 Docker Compose 启动 Tomcat 和 MySQL 服务,需要编写一个 `docker-compose.yml` 文件来定义这两个服务及其依赖关系。 ```yaml version: '3' services: mysql: image: mysql:latest container_name: mysql_container environment: MYSQL_ROOT_PASSWORD: examplepassword MYSQL_DATABASE: testdb MYSQL_USER: user MYSQL_PASSWORD: password volumes: - db_data:/var/lib/mysql command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true --lower_case_table_names=1 tomcat: image: tomcat:9.0 container_name: tomcat_container ports: - "8080:8080" depends_on: - mysql volumes: db_data: ``` 此配置文件中: - **mysql**: 配置了一个基于官方 MySQL 映像的服务实例。设置了环境变量以初始化数据库设置,并指定了持久化的命名卷 `/var/lib/mysql` 来保存数据[^2]。 - **tomcat**: 使用官方 Tomcat 版本 9.0 的映像启动 Web 应用服务器。通过端口映射使外部能够访问到该服务运行的应用程序。还设定了对 MySQL 服务的依赖性,确保先启动 MySQL 再启动 Tomcat[^1]。 上述配置允许两个容器之间相互通信,并且可以通过主机上的特定端口 (如 8080) 访问 Tomcat 提供的服务;而 MySQL 数据库的数据则会被安全地存放在由 Docker 管理的一个名为 `db_data` 的命名卷内。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值