[英]How do I create a docker container with two Java applications and Mysql server?
I have a Java application consuming binlogs from Mysql database and interacting with another service which I have hosted on my localhost.我有一个 Java 应用程序使用来自 Mysql 数据库的二进制日志并与我在本地主机上托管的另一个服务进行交互。 How do I create a Docker image with all these services so that I can run them all at once?
如何使用所有这些服务创建 Docker 映像,以便我可以一次运行它们?
From what I've heard, I need to use docker-compose.据我所知,我需要使用 docker-compose。 But I don't really know how to?
但我真的不知道该怎么做? Do I create separate Docker containers and link their ports?
我是否创建单独的 Docker 容器并链接它们的端口? Do I create one container?
我要创建一个容器吗?
I have created one Dockerfile for the Java application:我为 Java 应用程序创建了一个 Dockerfile:
FROM maslick/minimalka:jdk11
WORKDIR /app
EXPOSE 8080
COPY target/foster-maxwell-uber-jar.jar foster-maxwell.jar
COPY config.properties config.properties
CMD java -jar foster-maxwell.jar --config_type MAXWELL_UNSIGNED_KAAS --kaas_config config.yml --zk_timeout 1000
How do I go about it?我该怎么做 go 呢? Sorry for the noob question.
对不起菜鸟问题。
You should read docker-compose documentation: https://docs.docker.com/compose/compose-file/您应该阅读 docker-compose 文档: https://docs.docker.com/compose/compose-file/
For example, try with a docker-compose.yml file like this例如,尝试使用像这样的docker-compose.yml文件
version: '3.8'
services:
your-java-app1:
build:
context: . <-- (dir where you have your Dockerfile)
dockerfile: Dockerfile
image: yourjavaapp1image:1.0
container_name: your-java-app1
depends_on:
- db
your-java-app2:
build:
context: . <-- (dir where you have your Dockerfile_for_app2)
dockerfile: Dockerfile_for_app2
image: yourjavaapp2image:1.0
container_name: your-java-app2
depends_on:
- db
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: [put here your root pass]
MYSQL_DATABASE: [put here your db name]
MYSQL_USER: [put here your user]
MYSQL_PASSWORD: [put here your pass]
Once you have this defined your Dockerfiles, first, build images with your apps:一旦你定义了你的 Dockerfile,首先,用你的应用构建镜像:
docker-compose build
Then, run images (container creations)然后,运行图像(容器创建)
docker-compose up -d
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.