Consul and Tomcat in one docker container

This is a two-part question.

Part One: What is the best approach to run Consul and Tomcat in the same docker container?

I created my own image by installing both Tomcat and Consul correctly, but I'm not sure how to run them. I tried to put both calls in CMD in the Dockerfile, but did not succeed. I tried putting Consul as ENTRYPOINT (Dockerfile) and Tomcat to call in the docker run command. It may be the other way around, but I feel that it is also not good.

Docker will work in one instance of AWS. Each docker container ran Consul as a server to register with another AWS instance. The consul and consul template will be integrated into the correct load balance. This way my HAproxy instance will be able to redirect requests correctly when I connect or disconnect containers.

Second part: In separate tests I did, the docker container was able to get to my main server Consul (leader), but it could not register itself as a "live" node.

Reading the logs on the Consul server, I think this is a question of which ports I publish and publish. In AWS, I already allowed communication on all TCP and UDP ports between instances in this particular security group.

Do you know which ports I should expose and publish in order to ensure proper communication between the standalone consul (aws instance) and the consul servers (running inside docker containers in the aws container)? What is the command to launch the docker container: launch docker -p 8300: 8300 .........

Thanks.

+2
source share
1 answer

I would use ENTRYPOINT to run the script when docker starts.

Sort of

ENTRYPOINT myamazingbashscript.sh 

The syntax may be turned off, but you get the idea

The script should start both services, and finally should tail -f the tomcat logs (or any logs).

tail -f will prevent the container from exiting since the tail -f command will never exit, and it will also help you see what tomcat does

Make -f log dockers to view logs after starting docker

Please note that the container will not exit u, maybe it will execute into it ... docker exec -it containerName bash

This allows you to sniff inside the container.

Generally, the best approach is to use two services in one container, as it breaks down separation of problems and reuse, but you may have good reasons.

To build a docker assembly, then run using docker run as indicated by u.

If you decide to go to a container with two containers, then you will need to set the ports between the containers so that they can talk to each other. You can share files between containers using volume_from

+1
source

Source: https://habr.com/ru/post/1244126/


All Articles